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

I need help with this code challenge

In this challenge, you will create a while loop that prints to the document 26 times. We've added a variable named count, use it to track the number of times the loop runs. Don't forget to use the document.write() method inside the loop.

var count = 0; while ( count = 0 ) { var randNum = randomNumber(6); document.write(randNum + ' '); count += 1; }

4 Answers

Aleksandr Vinogradov
Aleksandr Vinogradov
12,113 Points
var count = 0;
while ( count < 26 ) {
var randNum = count;
document.write(randNum + ' ');
count += 1; }
Scott Kennedy
Scott Kennedy
9,212 Points

Theres no need for the extra variable.

var count = 0;
while ( count < 26 ) {
  document.write(count + ' ');
  count += 1; 
}
Julian Gutierrez
Julian Gutierrez
19,201 Points

A couple things need some attention in your solutions. First the condition in your while loop will only run 1 time because count will only be zero the first time around. To check equality in your condition you need two equal signs. (A single "=" is the assignment operator) There is no need for a random number the challenge; you will need to document.write the value of count

Robert Mckay
Robert Mckay
11,089 Points

This has been already answered - but I would like to point out one thing that might be helpful in the future. Make sure that your white space is used - it doesn't do anything for the JS - but it can help you spot errors in your own code and others code as well...just a thought.

Thanks Man!