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

Why do I get a "Bummer, your code took too long to run" statement? Is it my code or is it my internet?

var count = 0; while (count <=26) { document.write(count + ' '); count + 0; }

script.js
var count = 0;
while (count <=26) {
  document.write(count + ' ');
  count + 0;
}

2 Answers

Steven Parker
Steven Parker
173,603 Points

There's nothing in this code that changes the value of "count", so it will stay zero. And since that's less than or equal to 26, the loop condition will always be true and the loop will continue to run forever. This is often called an "infinite loop".

So since the program never ends, the validator is saying it "took too long to run".

One fix would be to add an equal sign on the last line and change the zero to one:

  count += 1;
Steven Parker
Steven Parker
173,603 Points

I checked the challenge instructions and it looks like you'll need one more fix: change the loop test to be just less than 26 (not "or equal").

This worked! Thanks.