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

Brian Guanzon
Brian Guanzon
3,155 Points

You need to assign a new value to the `secret` variable inside the loop.

var secret = prompt("What is the secret password?");

var password = 'sesame'; while(secret !== password){

prompt("What is the secret password?"); secret === password; }

document.write("You know the secret password. Welcome.");

app.js
var secret = prompt("What is the secret password?");
var password = 'sesame';

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

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>

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Brian, There are a couple of syntax issues with your code. First, you don't need to declare a variable with the password... that will be checked in the 'while' loop with the absolute value. (How you did it is correct in syntax, but it won't pass in the challenge just because of the way it was worded). Second, the secret===password will only cause you problems, because the 'while' loop is checking if it does NOT equal the password, so adding something that check if is DOES will only add confusion.

The code you are looking for is:

var secret = prompt("What is the secret password?"); //setting the input value to the variable secret

while (secret !== "sesame") {
       secret = prompt("What is the secret password?"); //checking to see if it is right, if not... do it again
}
document.write("You know the secret password. Welcome.");// when the password is correct

Hope this helps and Keep Coding! :)

Brian Guanzon
Brian Guanzon
3,155 Points

Thanks for helping. The question actually wanted me to write out a do.. while and I was finally able to work it out after a couple of tries. Thank-you!