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 trialphillip 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
231,275 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
231,275 PointsSteven Parker
231,275 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.