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

Zach Miner
Zach Miner
Full Stack JavaScript Techdegree Student 3,053 Points

Help w/ This challenge

Can someone help me with this problem. I can't figure out what's wrong with my code. Thank you.

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

do {
  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>

2 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,164 Points

Some hints:

  • Declare secret before the loop but don't assign it anything
  • Assign the prompt to secret inside the loop
  • Although I don't think it causes the challenge to fail remove the empty brackets after the loop
Jason Hill
Jason Hill
Full Stack JavaScript Techdegree Student 11,399 Points

As Kris mentioned, keep your mind on what you want to do inside the loop, and what data, variable, you are going to use inside the loop to compare. If that makes sense. I've been having the same issue myself, sometimes having the variable inside the wrong scope. If you read your loop carefully, and think about it as a small program, its stuck in a loop because it has nothing to compare secret too inside the loop.