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

Would this not work?

I keep getting this error "You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 152 times." this course seems to be very challenging and I am having issues knowing what I am suppose to do. I have yet to have a work space work the way it is suppose to when i follow along. Could it be from using let instead of var?

for ( let i = 1; i <= 156; i += 1) {
  if( i > 4 ) {

2 Answers

Steven Parker
Steven Parker
218,861 Points

The test "i > 4" doesn't include 4, so that will be missing from the output.

But an even better way to do this would be to initialize "i" to 4 in the loop, and then you don't need the test at all.

what do you mean initalize "i" to 4 in the loop? thank you for your time in helping. Steven Parker

Steven Parker
Steven Parker
218,861 Points

Initialization is the first of the 3 clauses of a "for" loop:

for (let i = 4;                    <-- initialization
                i <= 156;          <-- condition
                          i += 1)  <-- increment

Oh ok, I went back and made the changes and it worked flawlessly. Steven Parker Thank you so much!