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 trialQasim Rashad
Front End Web Development Techdegree Student 7,837 Pointshelp 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
33,778 PointsThere'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!
Qasim Rashad
Front End Web Development Techdegree Student 7,837 PointsQasim Rashad
Front End Web Development Techdegree Student 7,837 PointsWhen I got to the document.write function. Is there some specific I need to put between the parenthesis?
Gabbie Metheny
33,778 PointsGabbie Metheny
33,778 PointsNope, any valid string, number, boolean or declared variable should do it! The challenge just requires that something be printed to the document 26 times.