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 trialThristen Jones
3,442 PointsHow do I create a while loop to keep looping a prompt from user until the variable in the condition is matched?
// 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!");
let secret = prompt("whats is your secret)
do{alert "you you know the password"}
while(secret ===
2 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt looks like there's a few missing characters in your code, causing syntax errors. Don't worry, these are common hangups that can trip us all up from to time.
First of all its right that you put your actions in the do
part of your while loop and then put the experession in the while part.
First, take out the alert line and put it so that is within the do block of your while loop. Make sure you declare an empty variable called secret in the global scope (which means outside of the while loop).
Then in the while block provide the expression that checks the string "sesame"
// Display the prompt dialogue while the value assigned to secret
is not equal to "sesame"
let secret;
// This should run after the loop is done executing
do {
secret = prompt("What is the secret password?");
} while (secret !== "sesame")
alert("You know the secret password. Welcome!");
And then when that's done the program, and the correct string has been typed, will move on and then alert()
message will kick in.
jessicakincaid
21,834 PointsNote: You need to comment out /delete the variable declarations provided at the beginning of the code. I thought we were supposed to add to what was provided at the top so I was thinking about global vs. local scope but you can move secret and the alert (as above).
Thristen Jones
3,442 PointsThristen Jones
3,442 PointsTHANK YOU Jonathan! Bro it took me a looong time trying to figure this out and you helped me figure it out within a matter of seconds!