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

This code is not working

Just curious, not sure what i am doing wrong here, but i can't get this code to work

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

2 Answers

Wade Williams
Wade Williams
24,476 Points

Your current code sets counter equal to 10 and your while loop only runs if your counter is greater than 10. Since 10 is not greater than 10 it never runs. To fix this:

  1. Leave counter = 1;
  2. Make loop run while counter is less than 10
var counter = 1;
while ( counter < 11 ) {
    document.write("<p>Now in loop #" + counter + "</p>");
    counter += 1;
}

Thanks Wade