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 trialJennifer Riess
8,726 PointsLiterally this one is driving me crazy.
When I don't put the prompt in the do section:
The prompt() method should go INSIDE the do...while loop.
When I do:
You only need to call the prompt() method once, and only inside the loop. Hint: Declare the secret variable before the loop.
Argh! where is the loop??? Isn't do part of the loop? I don't understand the parameters.
var secret=prompt("What is the secret password?");
do {
secret = prompt("What is the secret password?");
if (secret == "sesame") {
document.write("You know the secret password. Welcome.");
}
} while ( secret !== "sesame" ) {
secret = prompt("What is the secret password?");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
cb123
Courses Plus Student 9,858 Pointshint: you only need to declare the secret variable. Only inside the loop do you need to ask the question. You won't need the if statement as the "while secret !== "sesame")" is doing the assessment for you. Once "sesame" is achieved then the program is free to go to the next statement which is the confirmation.
Hope that helps.
tobiastrinkler
Full Stack JavaScript Techdegree Student 16,538 PointsHi Jennifer, just try to declare an empty secret var before the loop and that should do it.