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

This is the code we used in the last code challenge. After learning about do...while loops, don't you think this would w

I think I added the conditions correctly in that will print welcome or will print try again in the while loop if the do section doesnt run what am I doing wrong

script.js
var secret = prompt("What is the secret password?");
var count=0;
var correctGuess;
 do{
 if(correctGuess===true){
   document.write("try again");

 }
 }
while ( secret !==false )   
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>
David Evans
David Evans
10,490 Points

You have an endless loop right now as correctGuess is uninitialized and is never updated.

If you want to use the correctGuess variable you can try something like this (following the challenge's previous code):

var secret,
    correctGuess = 'sesame';

do {
    secret = prompt('What is the secret password?');
} while (secret !== correctGuess) {
    document.write('You know the secret password. Welcome!');
}

Below is probably what they're looking for without your modifications of an extra variable:

var secret;

do {
  secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" ) {
  document.write("You know the secret password. Welcome.");   
}