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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Review while loops, do...while loops, and Loop Conditions

Emmanuel Mamon
Emmanuel Mamon
1,207 Points

What is wrong with my answer to the "Review while loops, do . . . while loops, and Loop Conditions quiz question"?

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 )

//my answer is 10 but I get, bummer it's the wrong answer//

1 Answer

the quiz ask that the console.log should print out 10 times. but remember that the code will run at least once before checking the condition of the while loop. to because it runs once it will need to only run 9 more times.

var x = 0;

do {

    console.log('I love JavaScript');

  x +=1;

} while ( x <= 9 )

I hope this helps.

Emmanuel Mamon
Emmanuel Mamon
1,207 Points

Thanks man. Cleared it up a lot