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 trialDominick Chism
8,857 PointsWould appreciate some clarification on how this works.
I was able to solve the problem, but after looking over it for some time I still don't understand how it works.
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = prompt("What is the secret password?");
do {
secret = prompt('')
} while ( secret !== 'sesame' )
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");
1 Answer
Steven Parker
231,269 PointsYour code isn't quite what was asked for, but it just happens to operate in a way that "tricks" the tester.
You were asked to only declare the variable outside the loop, and handle the prompting in just one place inside the loop. The tester first checks giving a non-matching response, so when your first prompt result gets discarded the tester thinks you've checked it and determined it to not match!
Then when it tries the correct response, the other prompt inside the loop gets it, and the loop ends, which is also as the tester expects, so you pass! The fact that the second prompt text is empty is apparently not checked by the tester.
As the challenges become more involved, the likelihood of a "false positive" like this will be become far more remote.