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

help with question

I'm having difficulties with creating a while loop, did I do something wrong?

var count = 1;
while (counter > 26) {
 document.write (RandNum);
  count += 1;


1 Answer

Gabbie Metheny
Gabbie Metheny
33,695 Points

There's a few things going wrong right now. Firstly, your variable is called count, but you're trying to reference it using counter. You'll need to change counter to count.

Secondly, you're saying that this loop should run while count is greater than (>) 26, which it won't be at the beginning (count = 1), so the loop will never run. You need to set it to run while count is less than (<) 26. You should also set count back to 0, that's what the challenge gives you at the start.

Thirdly, there shouldn't be a space between document.write and the parentheses, because you're calling the document's write method with the parentheses. document.write(randNum) still won't print anything, though, because no variable or function is delcared as randNum. You need to pass it a string (in single or double quotes), a number, a boolean, or a variable or function you've already declared (i.e. count).

Let me know if you need further clarification!

When I got to the document.write function. Is there some specific I need to put between the parenthesis?

Gabbie Metheny
Gabbie Metheny
33,695 Points

Nope, any valid string, number, boolean or declared variable should do it! The challenge just requires that something be printed to the document 26 times.