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 triallassek
8,209 PointsTask 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>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
3 Answers
<noob />
17,062 PointsYou 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.");
lassek
8,209 PointsThank'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
231,236 PointsAs you continue, you'll get to another task which will have you simplify the solution by using a different strategy.
lassek
8,209 Points@Steven, ok I can see that as a good approach to teach refining actually.
<noob />
17,062 PointsI 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