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

Hello, I am having trouble writing the while condition with this code challenge.

Anyone help me?

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

1 Answer

The challange asks to keep prompting the user WHILE the string secret is NOT EQUAL TO "sesame". You don't won't to use the ">" or "<" logic you want to check equality.

var secret = prompt("What is the secret password?");  //assigns the user input to a variable secret
while ( secret !== "sesame"){  // if the password the user entered was not equal to sesame then it runs the code insides the braces
     secret = prompt("What is the secret password?");  //asks the user for the password again
}

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

The while line should read:

while (secret !== "sesame"){