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

Alexandru Pescaru
Alexandru Pescaru
4,561 Points

can anyone help me ? i'm lost....

how to declare the variable secret before the loop ?

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

do {
  secret = prompt("What is the secret password?");    
}
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
202,104 Points

The declaration by itself (without calling "prompt") would simply be :point_right: var secret;