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

Zach Corpuz
Zach Corpuz
2,363 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
201,913 Points

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

Zach Corpuz
Zach Corpuz
2,363 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
201,913 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
2,363 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
201,913 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.