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 trialYemaya Re
Courses Plus Student 1,922 PointsVery confused by this question...
Hey team, I was doing a challenge and answered by placing a condition inside of the parenthesis: while ( counter < 10 ).... It was incorrect. Why, what did I miss or do wrong? Thanks!
Here is the challenge:
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?
var counter = 1;
while () {
document.write("<p>Now in loop #" + counter + "</p>");
counter += 1;
}
2 Answers
Steven Parker
231,269 PointsSince the counter starts at one, the condition "counter < 10
" will only run nine times. To run ten times the condition should be "counter <= 10
".
It would also work with "counter < 11
", but the intention would not be as clear.
Harold Thompson
18,157 PointsThanks Steven!!!
Douglas Palma
3,471 PointsDouglas Palma
3,471 Pointsthose off by one errors!
Steven Parker
231,269 PointsSteven Parker
231,269 PointsComputers can be so picky!
Happy coding!
Yemaya Re
Courses Plus Student 1,922 PointsYemaya Re
Courses Plus Student 1,922 PointsThank you, this loop lesson is a tricky one for me!