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

Chris Gainz
Chris Gainz
8,117 Points

Why won't my for loop work?

The third 'i' doesn't turn blue like the rest, it just stays gray and an error pops up saying parse error

script.js
for ( var i = 4, i <= 156, i) {

}

3 Answers

use semicolons insead of commas.

for ( var i = 4; i <= 156; i) {

}

Ari Misha
Ari Misha
19,323 Points

Hiya Christian! Here is the syntax for a "for" loop (just remember this syntax and you'll never get a "for" loop wrong)

for (initialization; boolean expression; steps ) {
  //magic happens here
}

If we compare your code with the syntax above, you've got your initialization correct, and boolean expression too. But seems like you're confused with the steps right? Challenge wants you to have steps of "1", consider it default when no steps are given in the challenge. Steps are "how many count you'd like to skip", right?

Here is the code:

for ( var i = 4, i <= 156, i += 1) {
   console.log(i);
}
Ernesto Samaniego
Ernesto Samaniego
4,598 Points

you are also forgetting to increment and log (i) to the console.