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 trial
Srdjan Cestic
6,855 PointsPrompt equal
var secret = prompt("What is the secret password?");
do {
prompt = prompt("What is the secret password?"); // Why is this prompt equal to prompt("What is the secret password?");?
secret = secret + 1;
if ( prompt == 'sesame') { secret = true; }
} while ( ! secret )
{ document.write("You know the secret password. Welcome.");
}
2 Answers
Sergey Podgornyy
20,660 PointsYou increment text variable. It will be always true. Your code should be, as the following:
var secret = 'sesame';
var pr;
do {
pr = prompt("What is the secret password?");
} while ( secret !== pr )
alert("You know the secret password. Welcome.");
Srdjan Cestic
6,855 PointsThanks for help!
Sergey Podgornyy
20,660 PointsYou are welcome ;)
Srdjan Cestic
6,855 PointsSrdjan Cestic
6,855 PointsMy code pass the challenge, but your code look shorter and thus better, but I just followed up to code I already get as start point in challenge, so I go that way.
Srdjan Cestic
6,855 PointsSrdjan Cestic
6,855 PointsCan you tell me where is problem with this code? In challenge said : Inside the loop, you should use the = sign to assign the value of a
prompt()to thesecretvariableSergey Podgornyy
20,660 PointsSergey Podgornyy
20,660 PointsYou will assign sesame with prompt, if you will
pr = prompt("What is the secret password?");And why you're trying to increment "secret" value?
secret = secret + 1;You should compare "secret" value with prompt, that you took from input. And you shouldn't increment word, which type is String. Only in those situations, when you have counter, or something like that, you need to increment value. But in this situation you need while loop to check if value in each iteration matches secret word (while it will be not
true). And counter in this loop will be result of prompt, that you take from input.See here, how while works http://www.w3schools.com/js/js_loop_while.asp