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 trialolu adesina
23,007 Pointsdo while loop helps
var x = 0; do { console.log('I love JavaScript'); x += 1; } while ( x <= ) Submit Answer
i put 10 but it seems i'm wrong a little help please
1 Answer
andren
28,558 PointsThis is a bit of a tricky question designed to catch you out, the answer is actually one less than you would think. This is due to the fact that x
starts at 0, not at 1. If you start counting from 0 and end at 9. then you have counted 10 numbers.
It's worth nothing that this is the case because the less than or equal to (<=) condition is used. If the condition had simply been less than (<) which is pretty common as a starting condition in loops like this, then the loop would stop one number before the one provided. Meaning that a condition of (x < 10) would actually result in 10 runs of the loop.
Michelle Cannito
8,992 PointsMichelle Cannito
8,992 PointsWe're not supposed to just give the answer, so here are some hints: