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 trialS Ananda
9,474 PointsHelp with do... while loop
All it said was try again. Don't know what I'm missing can someone help me see my mistake?
''' var secret; /* Secret password*/ var correctGuess = false; /Runs when they guess the correct answer/
do { secret = prompt("What is the secret password?"); if(secret === correctGuess){ correctGuess=true; }
} while (! correctGuess){ document.write("You know the secret password. Welcome.");
} '''
Thanks
var secret; /* Secret password*/
var correctGuess = false; /*Runs when they guess the correct answer*/
do {
secret = prompt("What is the secret password?");
if(secret === correctGuess){
correctGuess=true;
}
} while (! correctGuess){
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>
1 Answer
Jeremiah Bushau
24,061 PointsHello, looks like you just need to fix up the syntax a little, remember to check for "sesame" instead of correctGuess and move the document.write() up into your if block. Here is an example.
var done = false;
var secret;
do {
secret = prompt("What is the secret password?");
if (secret === "sesame") {
document.write("You know the secret password. Welcome.");
done = true;
}
} while (!done)
S Ananda
9,474 PointsS Ananda
9,474 PointsThanks Jeremiah, so much. Sometimes I just can't see simple things, like leaving out "sesame." Got it to run and understand my error, so am good to go.