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

Ryan Abbott
Ryan Abbott
5,822 Points

Syntax error

Im not sure where is my JS challenge I'm going wrong?

var secret = prompt("What is the secret password?");

while (secret /== 'sesame') { return secret; }

document.write("You know the secret password. Welcome.");

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

while (secret /== 'sesame') {
  return 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>

3 Answers

Abe Layee
Abe Layee
8,378 Points

I just did the challenge and you are not ask to use the return statement. You have to add secret var inside the while loop to prompt the user for the secret password. Remember, while loop will run untill the statement is evaluated to false. A true loop is called an endless loop which mean the code will run untill the browser crashes or unless you add a break statement after the while loop.

var secret = prompt("What is the secret password?");

document.write("You know the secret password. Welcome.");

while(secret !=='sesame') {
   secret = prompt ("What is the secret password?");
}
Abe Layee
Abe Layee
8,378 Points

The error is from this section of your code.

 while (secret /== 'sesame')

it should be

while (secret === 'sesame')
Ryan Abbott
Ryan Abbott
5,822 Points

This is the question "The code in app.js just opens a prompt, asks for a password, and writes to the document. Something is missing. Add a while loop, so that a prompt keeps appearing until the user types "sesame" into the prompt."

My statement should of had a !== not /== like I had. But even with that im still getting an error.