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 trialJustin Olson
13,792 PointsActivity help plz
Hello all! So far, loving this course, but finally got stuck on this activity. After a while, I put together the following code:
var correctPw = false;
var guess;
var password = 'sesame';
do {
guess = prompt('What is the secret password?');
if (guess === password) {
correctPw = true;
}
} while ( ! correctPw );
document.write('You are correct!');
It was much uglier than that, and for a bit I wasn't able to move forward as I couldn't get my code to work. I ended up tossing this into jsbin to find my errors. I was able to clean it up, tossed it into the activity, and it said it passed. YAY!!! ...but, here is my issue. After I completed the activity, I decided to run the code in jsbin just to see my work come to life. The prompt appeared, asked for the secret word, and i put some random stuff expecting the box to pop back up asking to try again. Nope, it said my gibberish was the secret code. So, I have two questions...
What is wrong with my code for it to say anything is the pw?
If my code technically is incorrect, why did it pass the activity? If I didn't double check it, I would have thought I was doing this correctly, and I would have been wrong.
Thank you for any answers friends!
1 Answer
Unsubscribed User
8,841 PointsHi Justin,
I executed the code in my browser and it worked for me. Your code is perfectly correct.
Thanks, Aishu
Justin Olson
13,792 PointsJustin Olson
13,792 PointsThank you for the confirmation. After seeing you post this, I tried it again in jsbin and it was still saying anything I put in the prompt was the answer. I opened a new workspace, tried the identical code again...and you are absolutely correct, it is working properly! This was a very motivating accomplishment, thank you again for your input.