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 trialJustin Warren
7,805 PointsHello! A bit confused about where to go with this one! Any help/explanation for this would be great.
It seems like you want the prompt to come up with the do loop at least once. And the answer is sesame. Then you want the loop to continue until the user types sesame. And I'm assuming sesame can't be case-sensitive. Please let me know if I'm getting the concepts right b/c I'm trying to do that, but I feel like I have a tough time always know what code makes things happen!! Help please !
do {
secret = prompt("What is the secret password?");
if (secret == "sesame") {
secret = true;
}
}
while ( secret !== "sesame" ) {
secret = prompt("What is the secret password?");
}
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>
2 Answers
Brian Jensen
Treehouse StaffYou were on the right track logically for sure, but the do while loop already has conditional statement built in. So you don't need to add if or true/false.
From MDN:
An expression evaluated after each pass through the loop. If condition evaluates to true, the statement is re-executed. When condition evaluates to false, control passes to the statement following the do...while
Also you just need to declare secret var outside of loop.
var secret;
do {
secret = prompt("What is the secret password?");
} while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
Justin Warren
7,805 PointsGot it figured out thanks so much!