JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Review Loops

Andrew Penn
Andrew Penn
3,385 Points

loop

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

why this statement is wrong?

2 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
53,478 Points

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.

Andrew Penn
Andrew Penn
3,385 Points

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