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

Run while loop 26 times

I keep getting that it takes too long to run and I want to be sure that I have the code right

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

document.write(count);
count += 1;  
} 

3 Answers

Michel Näslund
Michel Näslund
18,583 Points

Code below passes the test.

Your code runs 27 times because you are using the operator <= ("smaller or equal").

var count = 0;
while (count<26){

document.write(count);
count += 1; 
} 
Logan R
Logan R
22,983 Points

You've almost got it! The issue is your while loop. Right now you are doing while (0 <= 26). The issue with this is that both 0 and 26 never change. You'll want to change the zero to a variable that you are constantly updating in the while loop.

Hope this helps!

I Have altered the code a little bit but it still tells me that the code took too long to run

Logan R
Logan R
22,983 Points

Did you replace the 0 with the count variable? What does your code look like now?

I replaced the 0 with 1 but still it reads out to me "Bumper, your code takes too long to run"