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 trialPhil Nickel
2,077 PointsWhile loop
How I win this challenge?
var secret = prompt("What is the secret password?");
while ( secret !== "sesame" ) {
echo "false password";
}
document.write("You know the secret password. Welcome.");
<!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
Treehouse TeacherWell let's try with a hint. 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!
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.