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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Mike John](https://secure.gravatar.com/avatar/1e9238eaa20604ce280c9179ee387f36?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Mike John
3,182 PointsCan anyone please help me with this code challenge..?
Can anyone please help me with this code challenge..?
var secret = prompt("What is the secret password?");
var i = 0;
while(secret !== "sesame")
prompt("That's not it! Try again");
i +=1;
}
else if( secret === "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>
1 Answer
![Andreas Nyström](https://uploads.teamtreehouse.com/production/profile-photos/9387982/micro_profile.jpg)
Andreas Nyström
8,887 PointsHi. You don't need a var i in this one. All you got to do is change the if to a while loop. The while loop then checks if password !== "sesame". If it is not "sesame" the while loop continues because password NOT EQUAL TO "sesame" is true.
You then just need to write the other message outside the loop. Because if password === "sesame" then the statement is false and it jumps out of the loop.
You can also not use an else if if you dont first have an if. And you don't need that for this. This is what it should be like, try to understand what happening or ask if you have any questions. Cheers buddy!
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.");
Mike John
3,182 PointsMike John
3,182 PointsThanks a lot Andreas.!
Andreas Nyström
8,887 PointsAndreas Nyström
8,887 PointsAnytime, Mike! If you see this as the solution, please mark it as "best answer".
Thanks.