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

Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Don't understand

I don't understand the question...

I put a counter in the while but is wrong...

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

2 Answers

rydavim
rydavim
18,814 Points

You've got the right idea, but in your code, your while loop will only run if counter is strictly equal to 11. You want your loop to run any time counter is less than 11, so that it will run repeatedly.

var counter = 1;
while ( counter < 11 ) {  // You'll need to change strictly equals to less than.
    document.write("<p>Now in loop #" + counter + "</p>");
    counter += 1;
}
Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Jeff Lemay - rydavim

Thank you both!

I'm tired and I've been lost in an easy question...

..I'm also a beginner....

THANK you for helping me.

Cesare

Jeff Lemay
Jeff Lemay
14,268 Points

Your condition in the while loop should be (counter < 11)