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

Zaal Rottunda
seal-mask
.a{fill-rule:evenodd;}techdegree
Zaal Rottunda
Full Stack JavaScript Techdegree Student 1,796 Points

Infinite Loops Quiz: Given the code below, what will print to the console?

I have tried every answer on this question but am constantly told it is wrong. Not sure if a bug, but I thought the answer should be 'goodbye'.

while (false) { console.log('Hello'); } console.log('Goodbye');

Rohald van Merode
seal-mask
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey Zaal Rottunda 👋

You've posted this question in the general JavaScript discussions so I'm not entirely sure what quiz you're referring to. Could you please share a link to the quiz you're working on?

Since you're enrolled in a Techdegree you could also reach out to our Slack channels. We got dedicated staff and moderators available there throughout the day and are more likely to get a speedy response over there 🙂

2 Answers

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Thanks for sharing a link to the quiz! Looks like there are no duplicates in the quiz. First one is a do...while-loop:

do {
  console.log('Hello');
} while (false);
console.log('Goodbye');

For this question the do part of the loop will always run, no matter the condition. Therefor the result for this one will be: Hello Goodbye

The other question is the snippet you shared above, which is a while-loop.

while (false) {
  console.log('Hello');
}
console.log('Goodbye');

This block will only run while the conditional evaluates to be true. Since false will never evaluate to be true, the code inside will not run and the answer for this question is indeed: Goodbye

Hope this clears things up! 😃