Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look At Loop Conditions

Task 1 not accepting a solution

Seems to be a flaw in this exercise: the following solution isn't accepted:

var secret ;

while (secret=prompt("What is the secret password?") !== "sesame") {}

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

I get this message: Bummer: Use the strict not equals operator -- !== -- to compare the variable secret and the string 'sesame'.

app.js
var secret ;

while  (secret=prompt("What is the secret password?")!=="sesame") {}


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

You are close. you are being ask to use the while loop and handle what happens if the pass is not “sesame”. for that you just need to use the while loop and check it secret is not password, if it’s not the password u keep prompting.

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

while(secret !== "sesame") { secret = prompt("That's not it! Try again"); }

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

Thank's for the reply. When re-reading the task, it states what I should change - and changing the var statement which is necessary with my solution isn't mentioned so strictly I'm not doing what I'm asked to do, and I guess therefore it's not accepting it (however giving a confusing error message)

Imo the "correct" solution looks like bad coding practice that shouldn't be taught since it unnecessarily repeats code, and there is a simpler solution.

Steven Parker
Steven Parker
218,760 Points

As you continue, you'll get to another task which will have you simplify the solution by using a different strategy.

@Steven, ok I can see that as a good approach to teach refining actually.

I think the solution is cleaner and more readable. you declare the variable at the top of the script in order not to create a new variable every check in the while loop in