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

Kit Howlett
Kit Howlett
3,175 Points

Don't understand why document.write() is not being called...

Hi,

I'm really not sure what I am getting wrong here. I get the following message: Bummer: The document.write() method wasn't called.

Can anyone solve this please and explain why?

Thank you!

script.js
var count = 0;
while (count > 26) {
 document.write("Testing Loops");
}
Kit Howlett
Kit Howlett
3,175 Points

I realised I needed to add:

var count = 0;
while (count > 26) {
 document.write("Test");
 count += 1;
}

but it is still not working

2 Answers

anthony amaro
anthony amaro
8,220 Points

hello kit the loop doesn't run because you are saying that count is greater than 26 which is false because count = 0

and then you have to increase count before you print it to the page. if you print it to the page and then increase it. then the first time the loop runs count is going to be 0 and when the loop ends count is going to be 25 not 26;

var count = 0;

while(count < 26) {
  count += 1;
  document.write(count);
}

hope this helps

Kit Howlett
Kit Howlett
3,175 Points

Hi Anthony,

Oh now I understand! Thank you so much!