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 trialHudson Lanier
6,329 PointsMy code works, but I'm getting an incorrect result.
Hi, I checked my code by running it in the console, and it worked. I was stuck on this for several days, but decided to move on. I'm not entirely sure why I'm not getting a correct result here. Please help.
var secret = prompt("What is the secret password?"); var correctPassword = false;
do{ prompt(secret) ; if(secret = "sesame"){ correctPassword = true } } while ( ! correctPassword ) document.write("You know the secret password. Welcome.");
var secret = prompt("What is the secret password?");
var correctPassword = false;
do{
prompt(secret) ;
if(secret = "sesame"){
correctPassword = true
}
} while ( ! correctPassword )
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
JEFF CHAI
7,564 Pointsvar secret;
do {
secret = prompt("What is the secret password?");
}while( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
You starting need to declare secret as variable. Once you set it into a variable, continue get in do...while loop. In this do..while loop, it will keep on asking the user to key in the secret password when the password is not match up the condition 'secret !=="sesame" ' When the condition is true, it will break out from the loop and continue your following query.
Paul Walker
28,904 Pointsvar secret = 'sesame';
do { secret = prompt("What is the secret password?"); } while( secret !== "sesame" ) { document.write("You know the secret password. Welcome."); }
Paul Walker
28,904 Pointsvar secret = 'sesame';
do {
prompt("What is the secret password?");
}
while ( secret !== "sesame" ) {
secret = "What is the secret password?";
}
document.write("You know the secret password. Welcome.");
JEFF CHAI
7,564 PointsJEFF CHAI
7,564 PointsYour code is work, but have a mistake there.