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 trialStellah Avanthi
Front End Web Development Techdegree Graduate 18,685 PointsJust wondering even after adding the if condition for this do while loop it still throws an error, can anyone help.
Just wondering even after adding the if condition for this do while loop it still throws an error, can anyone help.
var secret = "sesame";
var correctGuess = false;
do {
prompt("What is the secret password?");
if (parseInt(secret) === "sesame") {
correctGuess = true;
document.write("You guess Right!!!");
}
while (parseInt(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>
1 Answer
KRIS NIKOLAISEN
54,972 PointsYou have added a lot of unnecessary code to solve challenge but it will pass with the following tips
- Don't initialize secret with the password.
- Update
secret
inside the loop by assigning it the value from the prompt - Do not try to convert
secret
to an integer. The value from prompt and what you are comparing it to are both strings - You don't need to write anything inside the loop
- Since you created the
correctGuess
variable your condition to run could be while correctGuess is false
So like I said you can do it that way and pass the challenge but after this see if you can do it without the if statement and correctGuess variable