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 trialPratik Rai
6,856 Pointswhat is wrong with this. frustrating me.
I cannot get it through. any explanation would be appreciated.
var secret = prompt("What is the secret password?");
do {
secret = prompt("What is the secret password?");
} while ( secret !== "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="script.js"></script>
</body>
</html>
4 Answers
Chyno Deluxe
16,936 PointsOh I'm sorry i misunderstood the question. The problem with your code is that you have the var in two places with the same value. you should create the empty variable as a global scope var and then give it a value inside the do loop.
Here is how you would write the code.
var secret;
do {
secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" );
document.write("You know the secret password. Welcome.");
Pratik Rai
6,856 Pointsthanks you. I understand what you say but this code doesn't pass the test.
Pratik Rai
6,856 Pointshmmm this makes sense. thank you. btw I don't like these javascript tutorials as much as <a href="http://channel9.msdn.com/Series/Javascript-Fundamentals-Development-for-Absolute-Beginners/Series-Introduction-01">Bob tabor's tutorials</a>.
Chyno Deluxe
16,936 Pointshaha. yeah its rough but if you haven't tried codecademy's tutorials i recommend it. Their JavaScript course was easier to understand.
Pratik Rai
6,856 Pointsyes I already finished it and the bob tabor's as well. but after starting with dave makes me feel myself like an infant. and the worst part I am just waiting this javascript's end so that I can only proceed to the next part.
Chyno Deluxe
16,936 Pointshaha. hang in there bud.
Pratik Rai
6,856 Pointsthank you Colin. Chyno already helped me out.