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!
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

phillip smith
1,681 Pointswhats the answer and why
whats the answer and why
var counter = 1;
while ( ) {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
1 Answer

Steven Parker
228,026 PointsA "while" needs a conditional expression between the parentheses, and the one here has nothing but a space there.
To make it work correctly, you need a comparison using "counter" that will be true until the loop body has run 10 times.
phillip smith
1,681 Pointsphillip smith
1,681 PointsThank you for responding. So what would the counter comparison be?
Steven Parker
228,026 PointsSteven Parker
228,026 PointsA typical expression would be "
counter <
some_value" — I'll leave it up to you to figure out what "some_value" should be to make the loop run 10 times.