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 JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Complete the Loop

How 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.

script.js
var counter = 1;
while ( counter < 10 ) {
    document.write("<p>Now in loop #" + counter + "</p>");
    counter += 1;
}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

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

Thank you for your help, Jennifer