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

Zach Miner
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.

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.");
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

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