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

I need assistance with this for loop code

The error is telling me that the left side of this is not a reference. I don't understand. Please help.

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

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi Michael, you've got the right idea just a couple of minor things.

In your code you have called the console.log() twice, which is not needed. Also you are incrementing the i value inside the for loop (console.log( i + 1) which is not needed as this is done inside the parenthesis when we declare the for loop, like so:

//declare the i variable, execute the loop while i <= 156, increment i by 1 on each iteration of the loop (e.g 4 + 1 = 5)
for (var i = 4; i <= 156; i += 1) { 
  console.log(i); //print out the value of i
}

Hope that helps!!

Thanks again Grace,

I thought that was what I typed the first time. Ok.

Grace Kelly
Grace Kelly
33,990 Points

no problem, haha don't worry that happens to me too sometimes and then i look back and see i made a minor mistake. Just so long as you learn from it and progress onwards don't sweat :)