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

stage 1 simplify repetitive task with loops

var secret = prompt("What is the secret password?"); while( seame === welcome){ document.write("You know the secret password. Welcome."); secret += 1; }

app.js
var secret = prompt("What is the secret password?");
while( seame === welcome){
document.write("You know the secret password. Welcome.");
secret += 1;
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>

2 Answers

Gavin Ralston
Gavin Ralston
28,770 Points

Okay, so, first things first.

You've got most of the details written for you, a prompt which stores a user's password input, and the part where the document is updated telling the user they know the password.

All you really have to do is wrap that prompt (which gets the password try) in a while statement so it'll keep checking over and over til the user gets it right.

// set up a variable to hold the guesses
var user_guess = "";

// keep doing this til the user_guess equals "mypassword"
while (user_guess !== "mypassword" ) {
  user_guess = prompt("Enter your password");
}

// once we're past the while loop, do whatever you want next!

That's the "outline" for the challenge. Using the names and variables given in the challenge, something just like this example should work just fine.

Thanks :)

var secret = prompt("What is the secret password?"); while ( secret !== "sesame" ) { secret = prompt("What is the secret password?"); } document.write("You know the secret password. Welcome."); secret += 1;

this is working!