Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlexandra Velez
Front End Web Development Techdegree Student 9,313 PointsFor this do while loop, what changes to the code need to be made for it to check the password correctly?
I believe the while portion is correct. I've created a variable password to have a password definition.
Still, I am not sure what's missing from the code.
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = prompt("What is the secret password?");
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");
do {
let secret = prompt("What's the secret password?");
const password === 'sesame';
} while (password !== 'sesame');
1 Answer
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 20,928 PointsHey Alexandra,
Inside the first block of do
write a code that opens a prompt dialog
and store in the variable secret
.
Inside the while
write a condition
that checks while the secret !== 'sesame'
keep displaying the prompt dialog that asks users to enter the secret password.
If the users guess the right password sesame
the condition will be false and therefore it'll execute the alert message
let secret;
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
do{
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!");
If you would like to learn more about this loop
, check out this website: https://www.w3schools.com/jsref/jsref_dowhile.asp