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 trialAli Amirazizi
16,087 PointsWhat's wrong with my code?
The code is stuck in an infinite prompt loop, and I can't figure out how to pass the challenge.
var secret = prompt("What is the secret password?");
var guess = prompt(secret);
var correct = false;
do {
prompt(secret);
if (guess === "sesame") {
correct = true;
}
} while (!correct);
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
Chris Shaw
26,676 PointsHi Ali,
You seem to be confused with the operation of do..while
loops and what the challenge is asking for, some things to note.
- You have 3 separate
prompt
declarations, the challenge is only expecting one - You have created a new variable
correct
which is an unneeded condition in thewhile
declaration - The only code you need in the
do
execution is the call toprompt
See the below
var secret;
do {
secret = prompt("What is the secret password?");
} while (secret !== "sesame");
Happy coding!
Ali Amirazizi
16,087 PointsAli Amirazizi
16,087 PointsThank you much!