Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nick Hericks
Full Stack JavaScript Techdegree Graduate 20,704 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