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 trialNoquisi Burgess
2,714 Pointscan anyone show me how to recode this in the do while style because my code doesnt seem to be working. Thx
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.");
Above is the original problem and Below is the code I wrote to rephrase it into a do while loop which I dont understand the reason for not working
var secret; do { var secret = prompt("What is the secret password?"); if (secret === "sesame") document.write("You know the secret password. Welcome."); } while (secret !== "sesame")
1 Answer
KRIS NIKOLAISEN
54,972 PointsThe error message you receive is you should declare secret before the loop which you have done. But you also declare it a second time inside the loop. Remove var
inside the loop so it is just secret = prompt...
Noquisi Burgess
2,714 PointsNoquisi Burgess
2,714 Pointsthank you so much! duuh smh, in hindsight its so simple but thx for getting back to me so soon to help me finish the challenge and move on.