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 Create a `do...while` loop

Zach Miner
seal-mask
.a{fill-rule:evenodd;}techdegree
Zach Miner
Full Stack JavaScript Techdegree Student 3,053 Points

Help w/ This challenge

Can someone help me with this problem. I can't figure out what's wrong with my code. Thank you.

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

do {
  prompt("What is the secret password?");
} while ( secret !== "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="script.js"></script>
</body>
</html>

2 Answers

Some hints:

  • Declare secret before the loop but don't assign it anything
  • Assign the prompt to secret inside the loop
  • Although I don't think it causes the challenge to fail remove the empty brackets after the loop
Jason Hill
seal-mask
.a{fill-rule:evenodd;}techdegree
Jason Hill
Full Stack JavaScript Techdegree Student 11,399 Points

As Kris mentioned, keep your mind on what you want to do inside the loop, and what data, variable, you are going to use inside the loop to compare. If that makes sense. I've been having the same issue myself, sometimes having the variable inside the wrong scope. If you read your loop carefully, and think about it as a small program, its stuck in a loop because it has nothing to compare secret too inside the loop.