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 Review Loops

loop

var counter = 0; while ( counter < 7 ) { console.log(counter); counter += 1; }

why this statement is wrong?

2 Answers

If you are talking about this question:

Finish the code below so that the loop runs 10 times:

var counter = 0;
while ( counter < __ ) {
  console.log(counter);
  counter += 1;
}

The loop needs to run 10 times. Since counter is initialized to zero you will want to run the loop for values 0 through 9. This can be accomplished with the condition counter < 10.

Thanks, I did not notice that the loop has to run ten times. Thanks