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 trialShadi Delshad
1,674 PointsI'm unsure of why 10 is the wrong answer if the loop is supposed to run 10 times.
The question reads, "Finish the code in this loop's condition, so that 'I love JavaScript' is printed to the console 10 times". Therefore the answer I submitted was <=10. Why is this incorrect?
1 Answer
vikas rana
745 Pointsvar x = 0; do { console.log('I love JavaScript'); x += 1; } while ( x <= 9 )
Here the variable x is initialise with zero. So to run the do block 10 times we have to write 9 in while condition then the condition will be run from 0 to 9. If we write 10 instead of 9 the do block will be run 11 times i.e(0 to 10) in this question.
But if we remove = in while condition like [while ( x < 10 )] then value 10 will be answer.