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 trialDwight Schofield
2,686 Pointswhat's wrong with my answer?
i get a message saying that there is a parse error. i remember having to use "parseInt " to convert a number in the string form to a number that's not in string form. but i don't know how to use "parse" in other situations.
do {
var secret = prompt("What is the secret password?");
} while ( secret !== "sesame" ) {
document.write("You know the secret password. Welcome.");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
andren
28,558 Points"Parse error" in this instance refers to the fact that JavaScript had issues parsing your code, meaning that there is something wrong with how your code is laid out or the syntax you use that prevents it from properly understanding what you are trying to do.
The issue that is causing the parsing error is that you have an opening curly brace { after the while statement which does not belong there. If you remove it then the parse error goes away.
There is still another issue with your code though so it still won't pass after fixing that issue. The problem is that with the way your code is written the secret
variable is redeclared each time the loop runs, which is quite inefficient.
It is better to declare secret
outside the loop, and then just change the value stored within it in the loop (remember that you don't use the var
keyword when changing a variable, only when declaring it). Once you have done that you will be able to pass the challenge.
Marshall Wells
8,368 PointsThis helped me lol - awesome
Dwight Schofield
2,686 Pointsthanks Andren. very helpful...
Grace Ji
5,402 PointsThis works :)
var secret;
do {
secret = prompt("What is the secret password?");
} while ( secret !== "sesame")
document.write("You know the secret password. Welcome.");
Marshall Wells
8,368 PointsMarshall Wells
8,368 PointsA parse error means your code doesn't follow syntax. In the code above you have not closed your While loop....... you need a '}' after '...Welcome.");'