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 trialStanley Wilkins
685 PointsWhat is the prompt here?
I think I am close but what is the prompt we have to put inside the while loop? Why do I get error?
var secret = prompt("What is the secret password?");
document.write("You know the secret password. Welcome.");
while (secret!=="Welcome") {
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>
1 Answer
Tobias Helmrich
31,603 PointsHey Stanley,
a prompt is like an alert window that pops up and asks the user for an input. The reason why you're getting an error is because you have to prompt the user to enter the "secret password" until he knows the right word which is "sesame" in this case (not "Welcome"). So you have to put your document.write after the loop because then the user had the right word and the loop exited. Instead of the document.write statement just prompt the user inside of the loop so it will ask the user for the secret password as long as he doesn't type in "sesame".
But you can keep your first prompt outside of the loop as you need to have a first value to compare to the condition of the while loop.
Like so:
var secret = prompt("What is the secret password?");
while (secret !== "sesame") {
secret = prompt("What is the secret password?");
}
document.write("You know the secret password. Welcome.");
I hope that helps you to find the solution, if not or if you have further questions feel free to ask, good luck! :)
Stanley Wilkins
685 PointsStanley Wilkins
685 PointsI tried this one except for putting document.write() after the loop and naturally it didn't work. I got it now. Thanks for help.