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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

what did i do wrong?

i need help

script.js
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.");
index.html
<!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
Steven Parker
231,275 Points

One 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.

I still don't get it

Steven Parker
Steven Parker
231,275 Points

So what's the code look like now, after applying those hints?

Well 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
Steven Parker
231,275 Points

So did you complete the challenge, or do you need to show us your current code and get some more help?

I completed the challenge,

Steven Parker
Steven Parker
231,275 Points

Angelic Thomason — Good job! And you can mark a forum question solved by choosing a "best answer".
Happy coding!