JavaScript JavaScript Loops Simplify Repetitive Tasks with Loops Create a do...while loop

clifford dsouza
seal-mask
.a{fill-rule:evenodd;}techdegree
clifford dsouza
Full Stack JavaScript Techdegree Student 1,755 Points

You don't always need to use a counter or specify an exact number of times that a loop must run. All you need is a condi

You don't always need to use a counter or specify an exact number of times that a loop must run. All you need is a condi

script.js
let secret;
do {
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
  let secret = prompt("What is the secret password?");
   alert("Currently, no code checks the password.");
}
while  (secret !== 'sesame')
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

2 Answers

Rabin Gharti Magar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 18,454 Points

Hey clifford,

Remove let keyword and alert from your first code block and it should work fine!

After removing these, your code should look like this:

let secret;
do {
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
   secret = prompt("What is the secret password?");
}
while  (secret !== 'sesame')
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

Hope this helps!

Adam N
Adam N
66,219 Points

When you declare a variable with the let keyword, you're not allowed to redeclare it. For example, the following code produces an error:

let bob;
let bob = 5;

Fix this error in your program and you will be closer to passing this challenge.

Let me know if this helps!