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 trialKaisha Jones
6,366 PointsHi, I am having trouble figuring out the do while loop and not sure how to proceed.
Not sure if it's asking me to place line 2 in in the curly braces. Your guidance is appreciated
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = prompt("What is the secret password?");
let password = secret;
// This should run after the loop is done executing
// alert("You know the secret password. Welcome!");
do {
}
while ( secret !== 'sesame')
alert("You know the secret password. Welcome!");
2 Answers
cazepeda
6,099 PointsFIRST, erase everything in the script.js. The instructions on there are confusing as heck! But I understand that we need to use the do - while loop. The loop consisting of the prompt to capture what the user inputs. We must keep showing the prompt until the user enters sesame
into the prompt field. Ok so lets do it!
let secret; // create an empty variable for secret.
do { // start the do statement
secret = prompt("What is the secret password?"); // assign prompt() to secret and show user the field to enter answer.
} while (secret !== "sesame"); // check user input if `sesame` entered othewise run do {} statement.
alert("You know the secret password. Welcome!"); // if answer if correct display alert message.
Steven Parker
231,275 PointsYou do want the assignment to happen inside the loop. But the declaration should occur before (the current line is doing both).
And you shouldn't need to create a "password" variable, it can all be done using "secret".