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

Took to long to run

why does it keep saying took to long to run?

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

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 83,234 Points

This is what's known as an infinite loop. The loop has been given no instructions to cause the loop to end, so it'll just keep on running and running and eventually cause the browser, or whatever environment it's running on to run out of memory.

You might want to replace the string your passing to document.write in with the variable reference as well. and increment the value of that variable for the loop to work.

count++;