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

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

do {
} while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

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.