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 trialLevi Sanders
Full Stack JavaScript Techdegree Student 1,685 PointsDo While loop challenge
Hey guys. I'm looking for any help with this challenge. I understand the concept behind Do While loops, but I can't seem to put this code together to pass this challenge. What I have attached probably isn't close to the answer, but i'm going to move on for now. Anything helps, thanks.
let guess;
let secret = sesame;
correctGuess = false;
do {
guess = prompt("What is the secret password?");
if ( secret === sesame ){
correctGuess = true;
}
} while ( ! correctGuess )
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Steven Parker
231,275 PointsYou shouldn't need to create any new variables for the new version (like "guess" or "correctGuess").
Hint: Try re-using (but re-ordering) the original lines to create the new version, it might help avoid some of the syntax errors introduced here and keep the code more compact.
cazepeda
6,099 PointsFIRST, erase everything in the script.js. The instructions on there are confusing as heck! But I understand that we need to use the do - while loop. The loop consisting of the prompt to capture what the user inputs. We must keep showing the prompt until the user enters sesame
into the prompt field. Ok so lets do it!
let secret; // create an empty variable for secret.
do { // start the do statement
secret = prompt("What is the secret password?"); // assign prompt() to secret and show user the field to enter answer.
} while (secret !== "sesame"); // check user input if `sesame` entered othewise run do {} statement.
alert("You know the secret password. Welcome!"); // if answer if correct display alert message.