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

Katie Dunayczan
Katie Dunayczan
8,616 Points

I'm stuck and can't figure out why this code is wrong.

I'm just being told syntax error. I have tried looking up for loops on W3 and it looks like I'm writing it correctly but it's not working.

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

I tried this code out and it works fine. Are you sure there is no other code that causes the syntax error? The loop seems fine to me.

4 Answers

Katie Dunayczan
Katie Dunayczan
8,616 Points

There must have been a bug or something. I just ran the same exact thing and this time it passed. I had made no changes.

Instead of i += 1, try i++, like this

for (var i = 4; i<= 156; i ++) {
  console.log(i);
}
Katie Dunayczan
Katie Dunayczan
8,616 Points

I tried i ++ and I'm getting the same response "There was an error with your code: SyntaxError: Parse error"

The code you have up there works for me in the challenge. But I had some issued before too. Try clearing the browser chache and submit your code again.