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 trialDavid Enus
646 PointsI keep having this syntax error and i am stuck.Please Help!
I keep having this syntax error and i am stuck, can someone help me with the structure of this task please?
var counter = 1;
while (10< ) {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
3 Answers
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,473 PointsHi David! You're close! As the counter is equal to 1 at the beginning, in order to loop through 10 times, you can stop the loop when the counter is less than 11 rather than 10. Also, you need to check that counter is less than 11 specifically like so:
var counter = 1;
while (counter < 11 ) {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
Hope this helps! Let me know if you have any questions :)
Jacob Mishkin
23,118 PointsThe best way to go about this is to read the loop out loud. I know it sounds silly, but it works.
Here is the challenge question:
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?
So what we need to do is make this loop, loop 10 times.
Here is the starter code:
var counter = 1;
while () {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
when looking at this we can see a var counter that is set to the value of 1, and a while loop, that is using the counter var to to reloop itself with the +=1, right.
so read it out loud: while counter is less than or equal to 10 loop though the code.
the syntax for less than or equal to is <=.
Remember programming is a language, when in doubt of whats going on, try and read it out loud or to yourself, and see the logic in what your saying.
David Enus
646 PointsThank you both for your answers as they were both helpful.