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

How does this javascript challenge solve?!

Re-write the code to use a do...while loop.

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

1 Answer

Tim Strand
Tim Strand
22,345 Points

you are missing the do portion of your do while loop. you need to tell the program to do something while a condition is true so the answer would be

var secret ;
do {
    secret = prompt("What is the secret password?");
} while ( secret !== "sesame" );
document.write("You know the secret password. Welcome.");

Thanks bro ;)