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

script.js
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = prompt("What is the secret password?");
do {
 secret = prompt(sesame);
}
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

3 Answers

Steven Parker
Steven Parker
231,269 Points

The "do" is not complete yet. You still need the "while" with the condition clause after the code block. Also, you don't need the first "prompt" any more; and the second one needs the question as the argument.

Steven Parker
Steven Parker
231,269 Points

To avoid confusion, please use whole words and sentences in your comments! But for now, I assume you meant "What do you mean?" and need a bit more explanation.

The structure of a "do ... while" loop is like this:

do {
  // code goes here
} while (<conditional expression>);

Your code above has the "do" but not the "while" with the condition. You still need to add that part. You may want to review this part of the video;

Then, "sesame" is not a defined keyword. The "prompt" inside the loop should have a question in quotes just like the original one. That word "sesame" will be used (in quotes) in the condition for the "while".

Finally, you won't need the first "prompt" anymore now that it will be done inside the loop. Just keep the variable definition.

wdym

Tysm!!