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!
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 trial
sakchai charoensin
Courses Plus Student 1,112 PointsI'm stuck at the "do...while" loop challenge.
Could someone tell me what is wrong with my code?
var secret ;
var correctPass = false ;
var passWord = 1234 ;
do{
secret = prompt("What is the secret password?");
if( parseInt(secret) === passWord ){
correctPass = true ;
}
}while( !correctPass )
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

Piotr Manczak
Front End Web Development Techdegree Graduate 25,171 PointsTry this:
var secret;
do {
secret = prompt("What is the secret password?");
if (secret === 'sesame') {
break;
}
} while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");

leonardorubiano
Courses Plus Student 8,970 PointsHey sakchai,
Your answer looks correct. I tried it in the console and it seems to be working as expected. Have you tried restarting the challenge or refreshing the browser? Make sure you're not changing the names of the original variables.

sakchai charoensin
Courses Plus Student 1,112 PointsI have done to start but it still won't work. Anyway, I try as the suggestion above from Piotr Manczak. It works now, thanks for your kindly attention.
sakchai charoensin
Courses Plus Student 1,112 Pointssakchai charoensin
Courses Plus Student 1,112 PointsThank you very much, Piotr Manczak