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

analyn jane calado
analyn jane calado
3,523 Points

I'm stuck here!

please, i need your suggestions.

script.js
var counter = 1;
while (10) {
    document.write("<p>#10" + counter + "</p>");
    counter += 1;
}
analyn jane calado
analyn jane calado
3,523 Points

but it says there, Your code took too long to run.

Colin Marshall
Colin Marshall
32,861 Points

Did you check out my answer below? It's telling you your code took too long to run because you have an infinite loop in your code. The Treehouse code that checks your answer has a feature that will detect infinite loops and give you that error message.

1 Answer

Colin Marshall
Colin Marshall
32,861 Points

You have while (10) which is only testing if 10 is true or false. Integers will always return true so your loop will repeat forever. You need to have the loop check to see if the counter variable is less than or equal to 10 so that the loop quits when the counter is more than 10.

var counter = 1;
while (counter <= 10) {
    document.write("<p>#10" + counter + "</p>");
    counter += 1;
}
analyn jane calado
analyn jane calado
3,523 Points

oh!!! yeah.. it worked! hhmm, thank you so much.!