Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

Zach Corpuz
Zach Corpuz
3,374 Points

Having trouble turning this into a do...while loop

I dont understand what the while portion of this code should be. I would have thought that if secret === sesame then it would pass, but it is still saying I am getting this problem incorrect.

Steven Parker
Steven Parker
217,590 Points

Please show your complete code and we can help identify the issue.

Zach Corpuz
Zach Corpuz
3,374 Points

var secret = prompt("What is the secret password?"); do ( secret !== "sesame" ) { secret = prompt("What is the secret password?");
} while (secret !== "sesame") { {secret !== prompt ("What is the secret password?"); if (secret === "sesame") { document.write("You know the secret password. Welcome."); }

1 Answer

Steven Parker
Steven Parker
217,590 Points

Here's a few hints:

  • you'll only need to use "prompt" one time
  • before the loop, "secret" will only be declared but not assigned
  • a "do" loop has no conditional expression by the "do" (only by the "while")
  • a "do" loop also has no code body after the "while", only between the "do" and "while"

Give it another shot with those in mind.

Zach Corpuz
Zach Corpuz
3,374 Points

Hi Steven,

Thank you for this. I took the hints in mind and tried but still cannot figure out my Parse Error. For your third point, what other direction should I take this? The conditional expression was already provided by TeamTreeHouse when opening up the challenge task and its initial code. Also, the variable was already assigned by TeamTreeHouse with the initial code given for the Challenge. Should I be changing up the given code this much in these tasks?

Steven Parker
Steven Parker
217,590 Points

The basic structure of a plain "while" (as the code began with):

while (conditional expression) {
code body
}

But the structure of a "do...while" loop:

do {
code body
} while (conditional expression);

So you'll keep the provided conditional expression with the "while", but they both move to the end of the body.

See if that helps. If you still have trouble, post the new code after applying the hints using Markdown formatting.