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

Zoe Powers
Zoe Powers
1,908 Points

Do while loop

I have a syntax error and I am not sure why that is.

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


do {

 return 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>

3 Answers

Zoe Powers
Zoe Powers
1,908 Points

Never mind, I figured it out.

Armando Rosario
Armando Rosario
959 Points

Excuse my ignorance, what was the syntax error you noticed and figured it out? Im having a hard time looking for an error.

Zoe Powers
Zoe Powers
1,908 Points

If I remember correctly I had to give the variable no value before the do while loop (so it would look like var secret; instead of var secret = prompt(“What is the password?”); ) and then state the prompt “What is the password” within the loop.

Armando Rosario
Armando Rosario
959 Points

so in this case, would you have written within the loop: return prompt ("What is the password?"); ?

Zoe Powers
Zoe Powers
1,908 Points

I believe so? I can not recall exactly.