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 trialDurdona 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,719 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,719 PointsMarcus Parsons
15,719 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 :)