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 trialJade Hudson
1,593 PointsI'm sorry. This is bending my mind a little. What am I not getting here?
I've tried this every which way, but I'm missing something here.
for (var i = 3; i <= 155; i+= 1) {
console.log(i);
}
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Jade,
Everything is correct, except i
does need to be 4, and the condition needs to be less than or equal to 156, because the instructions say from 4 to 156. Right now, your code will start the count at 3 and end it at 155.
The way a for loops
works is the loop starts the first time with the initial value assigned (i = 4
), it then checks to see if the condition has been met or not, if it does, it will execute the code block (the console.log in this case). Then it will increment the value and run the loop again. Once it not longer meets the condition, it will not run the code block and will stop.
Hope this helps. :)
Keep Coding!
Trevor Johnson
14,427 PointsHi Jade,
Have your loop start at where you want it to log your numbers. You want it to count from 4 to 156, so I should start at 4 and include 156. Right now it starts at 3 and ends at 155. Check out the code I posted below. Hope this helps.
for ( i = 4; i <= 156; i ++) {
console.log(i);
}
Jade Hudson
1,593 PointsJade Hudson
1,593 PointsI'm trying to get it to count from 4 to 156. If it is going to start on four, I figure there needs to be three, as the variable i will get a +1 before the console.log runs. The same goes for it running last at 155 and a +1 to get 156.
Am I missing something vital here?