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 trialCesare Parmiggiani
8,017 PointsHOW?
How can i tell the secret is sesame!?
var secret = prompt("What is the secret password?");
while (secret !== sesame){
var sesame = "sesame";
var secret ;
}
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
Jacob Mishkin
23,118 Pointsyour really close on this, just switch the empty var secret with the var secret the equals the prompt. you want the prompt to run inside the while loop. and delete the var sesame the you want the input from the var secret to equal sesame not a new var.
Cesare Parmiggiani
8,017 PointsAh! Ok now I understood!
I have to declare the var outside the loop, than only "call" it inside, without declaring it.... i confused it with a function.
Thank you Jacob, very helpful!
Cesare
Cesare Parmiggiani
8,017 PointsCesare Parmiggiani
8,017 PointsHi Jacob...
I wrote this:
I have to strictly use the !==
It gives me this error:
Bummer! Don't use the
var
keyword inside the loop. You only need to declare thesecret
variable once, at the beginning of the script.Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 PointsI just edited your response to view your code properly.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsokay so first before we declare the loop we need a var called secret. then inside the loop we want to say while the input from the prompt does not say sesame loop again. So with what you have is really close the only thing you need to do is set the var secret as an empty var outside of the loop, then inside the loop have the var secret equal the prompt. remember outside you need to state var secret; inside the loop all you need to secret.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 PointsNot a problem, any time!