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 trialZach Corpuz
3,374 PointsHaving 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.
Zach Corpuz
3,374 Pointsvar 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
231,268 PointsHere'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
3,374 PointsHi 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
231,268 PointsThe 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.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsPlease show your complete code and we can help identify the issue.