Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

Please Help Guyz, its so easy but i am get stuck into it

Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method.

script.js
for (var i = 3; i<156; i++){
  console.log(i);
  i+=1;
}

5 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Initial value of i and end condition are not right, also you don't need to increment i in the loop body.

for (var i = 4; i<=156; i++){
  console.log(i);
}

firstly, start with your index variable (i) at 4, because the loop begins by running once. Then take out the additional i+=1 as you already have 1 being added to i for each loop in the arguments. it should look like this-

for (i=4, i<156, i+=1){ console.log(i); }

I hope this helps

William Li
William Li
Courses Plus Student 26,868 Points

umm ... you missed the var keyword for i declaration, also, the end condition should be i<=156

yeah, you're right.. I didn't mean to point in the wrong direction by making those mistakes.. but the main point I was making was that he needed to start at i=4 and to remove that extraneous i+=1.

Thanks. :)

Many thankx guyz

Sobin Sebastian
Sobin Sebastian
5,348 Points

for (i = 4; i <= 156; i++) { console.log(i); }

Rich Braymiller
Rich Braymiller
7,119 Points

what are you talking about? makes no sense...im reading all these responses and am more confused about this challenge!