Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

Jonathan Ankiewicz
Jonathan Ankiewicz
17,604 Points

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

cm21
cm21
150,854 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)

Jonathan Ankiewicz
Jonathan Ankiewicz
17,604 Points

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