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 don't get the question

I don't understand the question

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

3 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Jonathan,

The challenge wants us to create a for loop that will make every number from 4 to 156 print out on screen. The code you have is very close to doing that, but the middle clause in your for loop's header is throwing things off.

Your middle clause, which is the for loop's test (the for loop will keep going until this test condition is met), is attempting to set your counter variable, i, equal to 156 (a single equals sign updates the value of a variable... two equals signs, or ==, are used to test if two values are equal.) What you want the middle clause to do, in the case of this challenge, is assure that i is printed until it is incremented so much that it is a value greater than 156. The way to assure this is to test if i is less than or equal to 156.

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

Hope this helps!

Change i = 156 to i <= 156.

In the conditional part of the for loop, you're making an assignment instead of a comparison.

for (initialize; condition; increment)

Oh... seriously I didn't understand what they were asking for. I'll try it now