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

What's wrong with this code?

I don't see what's wrong. Can someone help me?

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

2 Answers

Bryan Peters
Bryan Peters
11,996 Points

Remove the semicolon from the last part of the for loop parameters:

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

Even though the other statements have a semicolon at the end of them, the last item should not have a semicolon in the conditions for your loop.

It's a bit confusing because every other statement you make in JavaScript ends in a semicolon, but this is a special syntax. Also, just so you know, you can use the auto incrementer instead of += for that loop -> i++.