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 Simplify Repetitive Tasks with Loops Create a do...while loop

What should I change here?

Hi all.

I don´t understand why this wont work. What do i need to include or type different? Thanks

script.js
do {
    secret = prompt("What is the secret password?");
    // code to run
  }
  while ( secret !== 'sesame') {
    alert("You know the secret password. Welcome!") };
Jamie Moore
Jamie Moore
3,997 Points

Hey Marc, what issues are you having with the code? I just ran it in my console and it asked me for a password, if I enter 'sesmame', I get notified I know the password. What else would you like the code to do?

2 Answers

Hi Marc,

You're really close to solving the challenge.

I tried you're code in the challenge and got the error

ReferenceError: Strict mode forbids implicit creation of global property 'secret'

Because the challenge is in strict mode you need to declare the variable secret.

Here's some info on strictmode

The variable must be declared outside of the function and doesn't need to be given any kind of value yet.

let secret;
do {
    secret = prompt("What is the secret password?");
    // code to run
  }
  while ( secret !== 'sesame') {
    alert("You know the secret password. Welcome!") };

Hope that helps!

Thanks for your help :-)