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 trialJason Peay
16,515 PointsHow to Run a Loop?
This is a nearly complete while loop, but something is missing. The loop should run 10 times, but it's not working at all. Can you fix it?
Bummer! The document.write() method was called 9 times. It should be called 10 times.
var counter = 1;
while ( counter < 10 ) {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
2 Answers
Jennifer Nordell
Treehouse TeacherYou're so close! You're missing a grand total of one character. It starts at one and will only run while counter is less than 10. So it will do it from 1 to 9 which means it does it 9 times... not 10. You can fix this by making the following change:
while ( counter <= 10)
That will make it run from one to 10... including 10 (so a total of 10 times). Happy coding!
Jason Peay
16,515 PointsThank you for your help, Jennifer