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 trialTaqwa R
1,852 PointsI'm stuck - what is wrong with my do while loop?
I tried to follow an example from the lesson as a model to create the do while loop for this challenge task. I can't figure out what I'm missing.
var secret;
var correctGuess = false;
var guessCount = 0;
do {
secret = prompt("What is the secret password?");
guessCount += 1;
if (secret === 'seasame') {
correctGuess = true;
}
} while ( correctGuess = true )
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
Josh White
3,630 PointsI believe that since you have the while() statement looking for correctGuess to be true that is where your running into an error. Basically what it is looking for is Hey while the correctGuess variable is true I want you to do this. If you change the while() to be while(!correctGuess) it will only continue to run the do loop until the variable to changed to true. It's just backwards. I'm assuming if you enter the wrong password the program will stop.
Sipann A.
30,234 PointsI think Josh is right. Your updated code (with while !correctGuess)) works fine here. Just to be sure, are you entering the correct password (since you have specified 'seasame' and not 'sesame') ?
Taqwa R
1,852 PointsTaqwa R
1,852 PointsThat doesn't seem to be the answer. I tried changing it it to ( ! correctGuess ) but I'm still getting the error message. :-/