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

Loek Weijts
Loek Weijts
6,159 Points

What i my mistake, the code isn't accepted. Bummer! You should declare the `secret` variable before the loop.

do {
  var secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" );

document.write("You know the secret password. Welcome.");

I haven't done this challenge yet, but I did run it in jsfiddle and it works. Maybe try declaring the variable secret outside of the loop.

1 Answer

Cole Wilson
Cole Wilson
7,413 Points

You can declare the variable outside of the loop so you don't have to keep creating a new variable everytime within the loop. Your code is very close.

This is what I did.

var secret;
do {
    secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" );

document.write("You know the secret password. Welcome."); 
Loek Weijts
Loek Weijts
6,159 Points

Thx! Glad i wasn't too far of