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

Bryan Castleman
Bryan Castleman
9,520 Points

Is the var secret which is defined before and outside of the while loop overwritten within the while loop ?

When the program runs it comes to the while loop and sees the var secret and sees it it is not equal to "sesame".

Is this when the while loop begins to execute everything within the {}? So within the while loop when a numerous amount of new prompts run they are set to the var secret.

Is this variable the same but also new ? Is it temporarily overwriting the var secret ? Or could I write while (potato !== "sesame") and set the prompt inside of the while loop equal to var potato ?

1 Answer

Not exactly. So what you would need to do in this case is first declare an empty variable (secret). then you would create the while loop that would run as long as the answer is not sesame. if the while statement is true(answer is not sesame) you will continue to ask the user what the secret password is. like below.

var secret;

while( secret !== "sesame" ) {
  secret = prompt("What is the secret password?");
}
Bryan Castleman
Bryan Castleman
9,520 Points

Actually I believe my question was cleared up by watching previous video lessons, especially the one's that described scope.