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 trialJoseph Falconer
Courses Plus Student 15,887 PointsIs this a bug in the quiz or am I missing something?
The blank space in this question is where I've put 10 in the parenthesis after while. But it says this is wrong! Have I misunderstood <=? Help me please and thank you.
Finish the code in this loop's condition, so that 'I love JavaScript' is printed to the console 10 times:
var x = 0;
do {
console.log('I love JavaScript');
x += 1;
} while ( x <= 10 )
2 Answers
Tobias Helmrich
31,603 PointsHey Joseph,
you have to write 9 in this case. You have to note that x starts at 0 in this case and the comparison operator is less than or equals and the loop body will be executed 10 times (from 0 to 9). In your case it would be printed out 11 times (from 0 to 10). I hope it's more clear now, if not feel free to ask further questions! :)
Joseph Falconer
Courses Plus Student 15,887 PointsThank you Tobias and Neill. Got it! Your explanations sorted it for me!
Neill De-Terville
3,753 PointsNeill De-Terville
3,753 PointsHi, the answer will be 9 because in a Do while loop it always adds the console.log first before it runs the loop to add the other 9.
In a while loop it only starts running the console.log after the loop runs.
Hope this helps.