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 trialMartin Bornman
Courses Plus Student 12,662 Pointswhile loop
I am stuck with the while loop.Can someone help me out please???
var secret = prompt("What is the secret password?");
while ( password === "sesame" ) {
var password = "sesame";
}
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
2 Answers
Ana Uribe
6,674 PointsSo the challenge is asking you to prompt: What is the secret password? to anything that is not sesame. Right now your condition is going to pass every time password is equal to sesame. You can change this with !== so everything that is not sesame prompts the question again. Then do secret=prompt("What is the secret password?") to the code block to be executed, this will keep the question coming until the password equals sesame.
var secret = prompt("What is the secret password?");
while(secret!== 'sesame'){
secret = prompt("What is the secret password?");
}
Amy Norris
9,718 PointsThe question is worded a bit oddly, but you don't need to add a variable for "password." The password is the result of the prompt (your "secret" variable). You want to compare that to the word you are looking for, "sesame". While the word entered is not sesame, you want to prompt them again.
Martin Bornman
Courses Plus Student 12,662 PointsThanks Amy !!!
Matthew Ashman
4,364 PointsThis part, personally threw me off. I was attempting to add a variable of: var seseme, and then, somehow integrate it into an if(); statement within the loop. Obviously, not the correct way of succeeding in this code challenge! Thanks for your explanation Amy.
Martin Bornman
Courses Plus Student 12,662 PointsMartin Bornman
Courses Plus Student 12,662 PointsThanks Ana !!!
geoffrey
28,736 Pointsgeoffrey
28,736 PointsMartin Bornman , don't forget to mark the best answer ;)