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 trialBence Szabó
5,885 PointsI need help in challenge task
Hello, this is my version:
var secret = prompt("What is the secret password?");
var password = 'sesame';
while ( secret !== password ) {
secret;
}
document.write("You know the secret password. Welcome.");
I dont know whats wrong with it.
3 Answers
Erik Nilsen
20,433 Pointsvar secret = prompt("What is the secret password?");
var password = 'sesame';
while ( secret !== password ) {
secret;
}
document.write("You know the secret password. Welcome.");
Lets step through your code. You take whatever the user inputs in the prompt and set it to secret. You then check to see if it matches the password, if it doesnt you call the value the user inputed not the prompt again. The code below is an example of how you could fix this. :)
var secret = prompt("What is the secret password?");
var password = 'sesame';
while ( secret !== password ) {
secret = prompt("What is the secret password?");
}
document.write("You know the secret password. Welcome.");
Aaron HARPT
19,845 PointsInstead of doing this: while ( secret !== password ) { secret; } document.write("You know the secret password. Welcome."); try an if/else statement:
if( secret !== password ) { secret; } else { document.write("You know the secret password. Welcome."); } hope that helps.
Bence Szabó
5,885 PointsAaron: Thank you the help, however I had to use the while loop in this case. Still thanks! :) Erik: It worked! I Think I get the problem, its a little misty for now, but going to practie more and more ;) Thank you!
Erik Nilsen
20,433 Pointsa prompt returns the value the user inputed, so that is what is stored in the variable. Not the actual prompt message.