Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

can someone help me? I stopped in this quiz for a few days and I reviewed the video several times but I don't understand

can somebody help me??

Hi, Is there a question in particular or is it every single question in the quiz that you are having trouble with?

every question

2 Answers

every question

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points
  1. Finish the code to create a do...while loop: just fill in the special words to create a DO - WHILE loop ;)
  2. Given the code below, what will print out to the console?
while (false) {
  console.log('Hello');
}
console.log('Goodbye');

A while loop needs to check if a condition is true or not in order to execute the code in the block. If the condition is false, the code in the block will not execute and the program will continue its work, aka will skip the code in the block and will execute the next line after the loop.

  1. Given the code below, what will print out to the console?
do {
  console.log('Hello');
} while (false)
console.log('Goodbye');

Pretty much the same as the while loop: if a condition is false, the program exits the loop. IMPORTANT! the do - while loop checks if the condition is true AFTER it enters the loop, aka it executes the code in the block at least once than checks the condition.

  1. Which of the following is an example of an endless loop - an endless loop is that one that never finishes and never stops executing the code in the block and brakes your browser ( most times ). Check in which case the condition never evaluates to false in order to exit the loop.
  2. Finish the code:
var x = 0;
do {
  console.log('I love JavaScript');
  x += 1; 
} while ( x <= ....);

x is 0, it prints the text once, x becomes 1 ( x += 1 ), checks the condition. How many times must it be checked in order to print the message 10 times? That's it! :)