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 trialAbson Chifodya
11,817 PointsThis is the code we used in the last code challenge. After learning about do...while loops, don't you think this would w
This is the code we used in the last code challenge. After learning about do...while loops, don't you think this would work better in the do...while style? Re-write the code to use a do...while loop.
var secret = prompt("What is the secret password?");
var count = 1;
do { secret !== "sesame"
secret = prompt("What is the secret password?");
count += 1;
}
document.write("You know the secret password. Welcome.");
while (count <= 10);
<!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
231,275 PointsThis wouldn't be proper syntax, and there are a few other issues:
- the "while" must come immediately after the brace ending the loop block
- the test expression on the same line as "do" is not proper syntax
- one advantage of a "do" loop is that only one call to "prompt" is needed
- if the "while" only tests the count, it will keep asking even if the word is correct
Rustambek Zokirov
4,308 Pointsdoes anybody know the answer to this challenge???
Steven Parker
231,275 PointsGive it your best "good faith" try, and refer to the hints I gave above. If you still have trouble, start a fresh question and include your code in it.