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 trialAnish Patel
5,537 PointsWhy is this not working ?
I made the do while loop but i am wondering why it will not let me pass the stage, it says declare the var secret outside the loop but i want the variable to constantly change until it says "sesame", so that it can then exit the loop
do {
var secret = prompt('What is the password?');
} while (secret !== 'sesame')
document.write('Well done!');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Daniel Gauthier
15,000 PointsHey Anish,
This challenge is looking for the following code:
var secret;
do {
secret = prompt("What is the secret password?");
} while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
It's better to declare the variable outside of the loop first, since if it was inside the loop you would be declaring the variable over and over, which is fairly messy.
This way, you declare your variable, then continually reuse the same version of the variable inside the loop.
Good luck with the course!
Anish Patel
5,537 PointsAnish Patel
5,537 PointsThanks for the help!