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

Angelic Thomason
Angelic Thomason
1,889 Points

what did i do wrong?

i need help

script.js
var secret = prompt("What is the secret password?");
function prompt(){  
}
do{
  secret = prompt("What is the secret password?");  
if( secret !== "sesame" ){
secret = true;{
}while(! 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

Steven Parker
Steven Parker
171,120 Points

One of the advantages of converting to a "do" loop is you won't need to ask the question in two places. You can just declare "secret" before the loop starts but you don't need to initialize it.

You can still use the same conditional clause in the "while" even after moving it to the end of the block. You won't need a separate "if" test.

And you don't need to define the function "prompt" — it's a system built-in.

Give it another shot and write again if you still have trouble.

Steven Parker
Steven Parker
171,120 Points

So what's the code look like now, after applying those hints?

Angelic Thomason
Angelic Thomason
1,889 Points

Well I figured out that I didn't need to ask the question above the do part in the loop but to just declare the var, and that I could just ask it in the loop that way it started the loop then the while part would find out if the question was answered right

Steven Parker
Steven Parker
171,120 Points

So did you complete the challenge, or do you need to show us your current code and get some more help?

Steven Parker
Steven Parker
171,120 Points

Angelic Thomason — Good job! And you can mark a forum question solved by choosing a "best answer".
Happy coding!