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 A Closer Look At Loop Conditions

I need help with the while loop in app.js regarding sesame.

Anyone out there

var secret = prompt("What is the secret password?");
 while ( prompt
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="app.js"></script>

2 Answers

You need to create a while loop that run as long as the password given is not "sesame".

var secret;
while(secret !== "sesame"){
  secret = prompt("What is the secret password?");
document.write("You know the secret password. Welcome.");
Adam Moore
Adam Moore
21,956 Points

Your while loop (although it doesn't even have an ending parenthesis), basically does nothing.

The while loop has to contain criteria in order to run the loop (as long as the criteria is true, it runs), so the while loop has to be set so that it runs "while" certain criteria are true, and in this case, what returns as TRUE has to be where the answer to the prompt "secret" is NOT equal to "sesame". So, inside the "while" parentheses, the statement has to be true (i.e., "something !== something else". Then, inside the brackets "{}" that come after it (i.e. "while (something !== something else) { something to do }"), is what should continue to run. Therefore, if the user types "bread", then the prompt "what is the secret password?" has to pop up again. The while loop should continue to run, and the prompt should run again, assigning the result of the prompt back to the variable "secret". So, you'll have to set the variable "secret" back to the prompt result INSIDE of the while loop.

I'm trying to give some pointers without giving away the answer, and I, myself, am on Treehouse to learn, not simply be told the answers. Therefore, hopefully this helps to guide you in the right direction. If not, I'm sure I or someone else will guide you more or give you the answer.

Hope this helps, and good luck!