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 Do while loop

var secret
do {
  prompt("What is the secret password?");
   } while ( secret !== "sesame" );
document.write("You know the secret password. Welcome.");

I have been trying to get this challenge right all day and cannot see why it won't work. Can anyone help me to find out the problem? Thanks in advance.

2 Answers

var secret;
do {
  secret = prompt("What is the secret password?");
   } while ( secret.toLowerCase() !== "sesame" );
document.write("You know the secret password. Welcome.");

You didn't store prompt. Make sure to store prompt then compare the state. Variable is to store something.

while(true) {
// doSomething();
}

Thanks so much for your help. I kept getting it wrong and changing so many things trying to fix it. I understand now what my mistake was.