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

William Monteith
William Monteith
1,377 Points

Why is my code not working

There is not clear instruction why my code isn't working

script.js
var secret = prompt("What is the secret password?");

do {
 secret;
} while ( 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>

1 Answer

Steven Parker
Steven Parker
172,335 Points

The prompt (and assignment of "secret") needs to be inside the loop.

Only "var secret;" should remain before the loop.