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 trialMIHA W.LEE
PHP Development Techdegree Graduate 25,452 Pointsdo..while loop
Hi, i have problem with quiz. The quiz say i need to loop 10 times, but i already input the number '10' into the while parenthesis, still doesn't work, Can someone tell me whats going on with this question?
2 Answers
KRIS NIKOLAISEN
54,971 Pointsvar x = 0;
do {
console.log('I love JavaScript');
x += 1;
} while ( x <= 9 )
The loop executes before checking the condition. The first log x = 0. Then there are logs for x = 1 through 9 including 9 for a total of 10.
KRIS NIKOLAISEN
54,971 PointsFor x <=12 the loop will stop when x = 13. Only the numbers 1,3,5,7,9,11 will have be logged.
For x <=15 the loop will stop when x = 17. At that point 1,3,5,7,9,11,13,15 have been logged.
MIHA W.LEE
PHP Development Techdegree Graduate 25,452 Pointsvar counter = 0; { console.log(counter); counter += 1; } (counter < 10);
So, i dont know i catch your words. But, according to your example, in this question, only log out 0 1 2 3 4 5 6 7 8 9, right?
at the first the var x = 1 is also count into the list? right?
MIHA W.LEE
PHP Development Techdegree Graduate 25,452 PointsMIHA W.LEE
PHP Development Techdegree Graduate 25,452 PointsSorry for the late reply, thank you for the reply and thank you so much KRIS! But i still have question if the loop executes before checking the condition, why the example below in the while parenthesis, doesnt appear x<=12, but x<= 15?
var x = 1; do { console.log('#' + x); x += 2; } while ( x <= 15 ) (This question also from the quiz)