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

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'.

var secret ;

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

document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="app.js"></script>

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
229,967 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