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

would I change the 'prompt' to be a variable or shall I console.log

script.js
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = password("What is the secret password?");
do {
  secret = password("sesame");
}
while ( password !== 'sesame' );

// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

1 Answer

Hi Jacquelyn,

You really seem to understand the logic behind how the do...while loop works, but you’ve removed the prompt function and replaced it with password. The problem is that prompt() is a function that JavaScript interpreters understand.

More specifically prompt() is a function which returns output. And that output is stored in a variable (if there’s a variable available with which to store it).

So in the original code, if I was prompted to enter a password, and I typed “bartholomew” into my keyboard, the variable secret would contain the string “bartholomew”. Then you could compare secret to ”sesame" to see if your program should break the loop.

password is not a function (unless you define it as one), and as such password("What is the secret password?"); is invalid syntax. (Error: password is not a function).

What I would do is go back to the original lines of code and simply wrap the secret variable declaration inside the do...while loop code block. And as far as the while loop condition, that looks good. You just want to make sure you’re comparing secret to “sesame” and not password to “sesame”.

I hope that makes sense. If you need a little bit more help, let me know.

Good luck, Coder.