Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops Working with 'for' Loops Create a for Loop

Have the right code, but it wont run.

This code console logs numbers 5-100 but it wont let me pass it through ugh.

//! For Loop
for (let i = 0; i < 100; i++) {
   if (i < 5) {
      continue;
   }
   console.log(i);
}

Mod edit: added markdown for code readability. Check out the "markdown cheatsheet" linked below the comment box for syntax examples.

2 Answers

Cameron Childres
Cameron Childres
11,759 Points

Hi Vincent,

Your code logs the numbers 5-99 since the condition of the for loop is "i < 100". If you change this to "i <= 100" then 100 will be included and you should be able to complete the challenge.

Thank you, I missed that one!

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi Vincent,

Your solution is an interesting one, but it works great. Nice job. But it doesn’t actually log all 5-100.

app.js
for (let i = 0; i < 100; i++) { 
  if (i < 5) { 
    continue; 
  } console.log(i); 
}

It logs 5-99. If you look close you’d probably figure this out on your own, but once i becomes 100, the i < 100 part of the for loop no longer evaluates to true, therefore the code in the code block isn’t executed, and i is not logged to the console.

That’s happened to me plenty of times.

Great work here! Keep it up, coder!

Thank you! Could not spot this for the longest time!