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 trialAngelic Thomason
1,889 Pointswhat did i do wrong?
i need help
var secret = prompt("What is the secret password?");
function prompt(){
}
do{
secret = prompt("What is the secret password?");
if( secret !== "sesame" ){
secret = true;{
}while(! sesame)
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>
3 Answers
Steven Parker
231,275 PointsOne of the advantages of converting to a "do" loop is you won't need to ask the question in two places. You can just declare "secret" before the loop starts but you don't need to initialize it.
You can still use the same conditional clause in the "while" even after moving it to the end of the block. You won't need a separate "if" test.
And you don't need to define the function "prompt" — it's a system built-in.
Give it another shot and write again if you still have trouble.
Angelic Thomason
1,889 PointsWell I figured out that I didn't need to ask the question above the do part in the loop but to just declare the var, and that I could just ask it in the loop that way it started the loop then the while part would find out if the question was answered right
Steven Parker
231,275 PointsSo did you complete the challenge, or do you need to show us your current code and get some more help?
Angelic Thomason
1,889 PointsI completed the challenge,
Steven Parker
231,275 PointsAngelic Thomason — Good job! And you can mark a forum question solved by choosing a "best answer".
Happy coding!
Angelic Thomason
1,889 PointsAngelic Thomason
1,889 PointsI still don't get it
Steven Parker
231,275 PointsSteven Parker
231,275 PointsSo what's the code look like now, after applying those hints?