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

Hyeri Chung
Hyeri Chung
2,178 Points

I can't understand what the question wants me to do anymore.

I think this code works for the asked query but I can't meet the expected answer to this question. will be appreciated if you can have a look for my code. what should I change for the answer? is it necessary to follow the question answer's instruction?

var password = 'sesame' var correctanswer = false;

do { var secret = prompt('what is the secret password?'); if ( secret === password ) { correctanswer = true; document.write('you guessed the right password. :p'); } } while ( ! correctanswer )

script.js
var password = 'sesame'
var correctanswer = false;

do {
 var secret = prompt('what is the secret password?');
 if ( secret === password ) {
    correctanswer = true;
   document.write('you guessed the right password. :p');
     }
} while ( ! correctanswer )
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,109 Points

For best results, always follow the challenge instructions and do exactly what they ask for and nothing extra.

Here's a few hints for this one:

  • you only need to call the "prompt" method once, and only inside the loop
  • declare (but don't assign) the "secret" variable before the loop
  • the inner body of the loop should stay the same
  • the line after the loop should stay the same