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.

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.");
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

2 Answers

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.