Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Durdona Abdusamikovna
1,553 Pointsmy answer runs ok in browser but here it is wrong
Here is my answer
var secret = prompt("What is the secret password?");
var password ='sesame';
while(secret !== password){
secret = prompt("please try again") //without using secret variable here I was not able to run a program I needed to call it again
if(secret === password) { // so I could use it in 'if'
alert("You are right ");
}else{
document.write("Try again ... ")
}
}
document.write("You know the secret password. Welcome.");
However I am getting error which says document.write should be declared outside the loop... when I am submitting my code in the challenge section
1 Answer

Marcus Parsons
15,718 PointsHey again Durdona!
The challenge doesn't want all of that information in your code. It just wants you to check secret
against the string "sesame" and not break out of the loop until it equals "sesame" like so:
var secret = prompt("What is the secret password?");
while (secret !== "sesame") {
secret = prompt("What is the secret password?");
}
document.write("You know the secret password. Welcome.");
Challenges are very specific about what they want! Your code is good and valid, but you should focus on using the bare minimum amount of code when doing challenges that way they will pass! :P
Durdona Abdusamikovna
1,553 PointsDurdona Abdusamikovna
1,553 Pointsin my previous assumption for the challenge I did the same case :) my answers for some reasons always deeper :( I need to keep them simple ... I spent more than an hour to figure it out then. Thank you :)
Marcus Parsons
15,718 PointsMarcus Parsons
15,718 PointsYou're very welcome! :) When doing your actual coding, stick to your guns on keeping your code user friendly and a good user experience as you seem to be well on your way to doing, but just for challenges, keep it simple. :P
Durdona Abdusamikovna
1,553 PointsDurdona Abdusamikovna
1,553 PointsI will hopefully :)