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

Morgan Walstrom
Morgan Walstrom
4,683 Points

why is this not correct?

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

script.js
for (let i = 4; i < 156; i++){
  console.log(i);
}
Morgan Walstrom
Morgan Walstrom
4,683 Points

It wants me to console log 4-156. I believe I nailed it but team treehouse won't pass me. The error is stating I have a syntax error but can't seem to see it...

1 Answer

andren
andren
28,558 Points

There are two issues, one which has to do with the code checker itself, and one that is an actual error in your code.

The first issue is that in JavaScript courses that was developed before Treehouse started teaching ES6 features (let, const, arrow functions, etc) the code checker is often not configured to deal with said features. So it will only accept older ES5 compliant code. In this case that means you have to use var instead of let.

The second issue is that since the condition of your loop is that i needs to be less than 156 it will stop once i becomes 156, which means that 156 is never actually printed out. The condition needs to be that i should be less than or equal to 156.

If you fix those two issues like this:

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

Then your code will pass.

Morgan Walstrom
Morgan Walstrom
4,683 Points

Thank you! Correct less than or equal to! I did happen to figure out the let and var issue but I do appreciate your input!