Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look At Loop Conditions

Phil Nickel
Phil Nickel
2,077 Points

While loop

How I win this challenge?

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

while ( secret !== "sesame" ) {
echo "false 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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well let's try with a hint. :smiley: Ok so you start by asking the user for a password, and you set their response into the variable secret. Then you say while secret is not equal to sesame. Let's imagine for a moment that I entered "Hello" because I didn't know the password. Your code will loop endlessly. Because "Hello" will never be equal to "sesame", and you've never given me a chance to try again. Somewhere in there you need to give the user an opportunity to try another word! Good luck! :sparkles:

edited for additional note

Someone else pointed out something earlier that I missed as well. You're trying to use echo, which isn't a valid way to output information with JavaScript. You can use document.write to write to the document, console.log to write to the console, innerHTML to write inside an HTML element, or use an alert to display a popup with information to the user.