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

Ruben Casillas
Ruben Casillas
6,019 Points

I need help on this one, I am stuck :(

I am not understanding, please help

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

2 Answers

Hey Ruben,

You're assigning the "Keep trying" string to the prompt like it's a variable. Instead, we need to use it with method syntax, as prompt() is a method.

Prompts are written like this -

prompt("Hello!");

Prompts return the value entered by the user, so we need to store that returned value similar to the first line written in the challenge. Since the while loop is checking if the secret variable does not equal "sesame" we'll need to store the new user value back into the secret variable.

  secret = prompt("Keep trying");
Ruben Casillas
Ruben Casillas
6,019 Points

Thank you so much ! It worked !