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

why is it taking too long?

why is it taking too long to run? is it an endless loop? I don't understand what I'm missing

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

1 Answer

Nick Hericks
Nick Hericks
Full Stack JavaScript Techdegree Graduate 20,642 Points

Hi Kim! You are correct in your assumption that the way it written above, this is indeed an endless loop. Right now your condition is (count < 26) which is actually saying "as long as the count variable is less than 26, keep looping."

To prevent this from looping forever, you will need to add an iterator inside the loop that increases the count variable. Here's one way to add an iterator inside this loop:

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

You could also write the iterator like this which does the same thing:

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

Also note that document.write() is a method so you'll need to include the () at the end. That is missing in the above code. After making those small changes, you should be passing with flying colors!!!

Hope this helps! Keep on coding!

thank you