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

Chaning to do while

HI,

HI,

I have to trnasform this code :

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

into

Im trying this code

var secret = prompt("What is the secret password?");
var password = "sesame";

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

ERROR : Bummer! You only need to call the prompt() method once, and only inside the loop.

I tried a lot, nothing works.

2 Answers

HI Konrad,

Like the message says, you only need to call the prompt method once and inside the loop.

And there's no need for extra variables as well.

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

Oh , wow , now it makes sense : p ill gonna need more practice on this . Thank you! :)

I got a question, how long would it take me aprox to learn enought JS to make someting useful from my own skill without looking on the videos?

We haven't learned about do...while loops yet, so something must have changed here (or maybe I'm losing my mind!). I can't get the code above to pass, I keep getting an error saying "Stick with a plain while loop for this challenge, not a do...while or for loop." Totally stuck. And why was a do...while loop passing 8 days ago and isn't passing now?

We covered it ^^

I dunno , im new to JS : p , i dont know the common mistakes ppl make etc..