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

Matt Fredericks
Matt Fredericks
5,399 Points

Not sure what's wrong for( var num = 4; num < 156; num+=1) { console.log(num); }

Not sure what's wrong with the for loop

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

3 Answers

You're close but you're actually only logging numbers 4 through 155. The way the logic of your for loop works is that it starts at 4 and keeps looping for as long as the variable is less than 156. When it reaches 156, it stops, and never logs it. So you want to go to 157.

for (var num = 4; num < 157; num++) {
 console.log(num); 
}
Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

Hey Matt,

Your loop seems to be working correctly; It is logging the numbers 4 to 155. Were you trying to achieve something else?

Best,

Clayton

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you will be one number short with this loop. you are very close. you need to make a minor tweak to include the missing number. run this code in your console and you will see.