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

Rachel Carter
Rachel Carter
915 Points

Code took too long to run

What is wrong?

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

2 Answers

Steven Parker
Steven Parker
229,670 Points

"Code took too long to run" is the euphemistic version of "This code is in an infinite loop."

When you wrote "count + 1;" it adds 1 to the count, but it doesn't store that computed result anywhere. To increment the count, you could use the addition assignment operator: "count += 1;"

Hey! If you want to change or add to the contents of a variable you need to use the "=" sign. Meaning that the code should go something like this:

count  = count  + 1;

And in your case, if you want to use the shortened version, then you can write it out like this:

count += 1;

So you're just missing the "=" sign in order for the code to work ;)

Hope this helps & good luck!