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

how to solve this

my code is nonsense can somebody help??

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

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

Kaetlyn McCafferty
Kaetlyn McCafferty
12,193 Points

You're almost there! First, you define the variable 'secret' (which is input from a user via a prompt).

Then we need a while loop that'll run so long as 'secret' (or what the user enters into the prompt) is NOT equal to "sesame" (so for this, we use !== ). In the while() statement, you don't need to include 'pompt', you only need the variable that's storing the information from the prompt - in this case, that variable is 'secret.'

Then, within that loop, we place code will keep running until the user enters "sesame" into the prompt; this code will prompt the user to enter something again, update the 'secret' variable, and check whether or not what the user enters is equal to "sesame".

When they do enter sesame, the loop will end, and then our document will print out the respective text.

Have a look:

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.");