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

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.