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 trialtomssleiners
1,152 PointsHi, I can't seem to find any syntax error with this snippet, could you please help me out?
There was an error with your code: SyntaxError: Parse error
... var secret = prompt("What is the secret password?");
do( secret === 'sesame' ) { document.write("You know the secret password. Welcome."); } while( secret !== 'sesame' ) { prompt("What is the secret password?"); } ...
var secret = prompt("What is the secret password?");
do ( secret === 'sesame' ) {
document.write("You know the secret password. Welcome.");
} while ( secret !== 'sesame' ) {
prompt("What is the secret password?");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Steven Parker
231,275 PointsIt looks like you're part way between converting a while
into do...while
.
- there won't be any conditional expression after the "do"
- you will only declare secret before the loop
- all of the other code lines will be inside the block between "do" and "while"
- you'll need to assign the result of calling prompt to secret
- you will only call prompt once — inside the loop
- there will not be a code block after the "while" (just a semicolon)
tomssleiners
1,152 Pointstomssleiners
1,152 PointsThanks Steven, it took me a while to understand, but eventually I did and now it makes sense.