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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Nazeim Brame](https://secure.gravatar.com/avatar/e1acffa5ca41b8f8403629b66fea832b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Nazeim Brame
6,544 PointsI don't know what to do. I'm following the steps, and its not working.
I don't know how to convert a while into a do while. This wasn't covered in the course, so I'm unfamiliar with the format. I don't know how to make it work the same.
var secret = prompt("What is the secret password?");
while ( secret !== "sesame" ) {
secret = prompt("What is the secret password?");
}
document.write("You know the secret password. Welcome.");
const secret = prompt("What is the secret password?");
do {
secret;
} while (secret !== "sesame")
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsSome hints:
- a "while" loop starts with the "while" keyword and a conditional expression, then has a code block
- a "do while" starts with the "do", then has a code block, and ends with the "while" keyword and expression
- a "while" block runs after the expression is tested, a "do while" block runs before the expression is tested
Perhaps that will help. If you're still stuck, you may want to review the do...while loops video, or look at some of the other forum questions about this same exercise.
UPDATE — here is the example code with comments added:
/* (original code)
var secret = prompt("What is the secret password?");
while ( secret !== "sesame" ) {
secret = prompt("What is the secret password?"); <-- re-use this line
}
document.write("You know the secret password. Welcome."); <-- re-use this line
*/
// any bits of the original code above not re-used should be removed
// no assignment needed here, and "const" can't be used for variables that will change
const secret = prompt("What is the secret password?");
// put the "var secret" declaration here (but no assignment needed yet)
do { // correct!
secret; // put the assignment from the original loop body here
} while (secret !== "sesame") // correct!
// move the "Welcome" message line here
![Nazeim Brame](https://secure.gravatar.com/avatar/e1acffa5ca41b8f8403629b66fea832b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Nazeim Brame
6,544 PointsThis doesn't help me at all Steven. I re watched the video 3 times. I need a solution so I can identify what I'm doing wrong. Thank you.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI've added a line-by-line commentary to my answer.