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 trialEdwin Abboud Blanco
Full Stack JavaScript Techdegree Student 4,747 PointsDoes anyone know the answer to this one? I'm stuck
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let sesame = true
let secret = prompt("What is the secret password?");
do {
let secret
} while (secret !== sesame)
alert("You know the secret password. Welcome!");
2 Answers
Steven Parker
231,275 PointsYou've got the right idea, but the code needs a few tweaks:
- the declaration of secret should be outside the loop
- the assignment of it should be inside the loop (and without the "let")
- the while condition should compare it to a string (with quotes)
- and you won't need to create a sesame variable
Alternatively, you could keep the extra variable, but just assign it to "sesame".
Charlie Palmer
15,445 Pointsyou would want to create the variable secret and leave it undefined. then in the same scope create a do-while loop whilst the secret does not store the string 'sesame'. inside of the do: change the value to the return of a prompt.
doing this will mean that the user will have to keep entering the secret until it matches the secret in the code.
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret;
do {
secret = prompt("What is the secret password?");
} while (secret !== 'sesame')
alert("You know the secret password. Welcome!");