JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

Azsha Preble
Azsha Preble
Full Stack JavaScript Techdegree Student 5,090 Points

Do... 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?

script.js
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.");
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

you dont need the if statement just document write.

Ezra Siton
Ezra Siton
12,350 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 ifstatement - 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..."