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 A Closer Look At Loop Conditions

Supratim Nandi
Supratim Nandi
3,287 Points

Glitch found in a question->while loop to move the prompt again and again ,until got the answer!

var secret = prompt("What is the secret password?");
 var count=0;

   while( count!==1)
   {         if(secret.toUpperCase()==="SESAME")
            {   
               count+=1;

            }

            else
            {
                secret=prompt("What is the secret password?");
            }
   }

   if(count ===1)
   {
     document.write("You know the secret password. Welcome.");
   }

[MOD: added ```javascript formatting -cf]

1 Answer

Karolin Rafalski
Karolin Rafalski
11,368 Points

In order for the while statement to run, the given condition must be true. But it doesn't have to be a number - it can be a string match or a boolean statement. The prompt is supposed to appear until the user gets the password (tries don't need to be counted when using while).

Instead of var count = 0

try

while (secret !== 'sesame') {
  secret = prompt ("That was not the password. Please enter the secret password");
}