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

Martin Bornman
PLUS
Martin Bornman
Courses Plus Student 12,662 Points

while loop

I am stuck with the while loop.Can someone help me out please???

app.js
var secret = prompt("What is the secret password?");
while ( password === "sesame" ) {
  var password = "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="app.js"></script>
</body>
</html>

2 Answers

Ana Uribe
Ana Uribe
6,674 Points

So the challenge is asking you to prompt: What is the secret password? to anything that is not sesame. Right now your condition is going to pass every time password is equal to sesame. You can change this with !== so everything that is not sesame prompts the question again. Then do secret=prompt("What is the secret password?") to the code block to be executed, this will keep the question coming until the password equals sesame.

var secret = prompt("What is the secret password?");
while(secret!== 'sesame'){
  secret = prompt("What is the secret password?");
}

The question is worded a bit oddly, but you don't need to add a variable for "password." The password is the result of the prompt (your "secret" variable). You want to compare that to the word you are looking for, "sesame". While the word entered is not sesame, you want to prompt them again.

Matthew Ashman
Matthew Ashman
4,364 Points

This part, personally threw me off. I was attempting to add a variable of: var seseme, and then, somehow integrate it into an if(); statement within the loop. Obviously, not the correct way of succeeding in this code challenge! Thanks for your explanation Amy.