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 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
231,236 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
231,236 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.