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 trialAzsha Preble
5,090 PointsDo... while loops are killing me
I greyed (noted?) out the original while loop. I'm supposed to turn it into a do... while... loop, but I can't figure out how. There are no hints, it just keeps coming back with a parse error. Can someone help me figure out where I'm going wrong?
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.");
*/
do { secret = prompt("What is the secret password?");
} while (secret !== "sesame")
if 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>
Ezra Siton
12,644 Points/* script.js */
var secret = prompt("What is the secret password?");
do {
secret = prompt("What is the secret password?");
if (secret === "sesame") {
document.write("You know the secret password. Welcome.");
}
} while (secret !== "sesame");
Related to you code your should put the if
inside the do
(Also you missing curly braces for if
statement - syntax error) - Useful test your code validation her:
https://esprima.org/demo/validate.html
In this code if the user write the correct password - he gets message "you know..."
darrin allen
7,775 Pointsdarrin allen
7,775 Pointsyou dont need the if statement just document write.