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 trialGareth Partridge
13,421 PointsThis is the code we used in the last code challenge. After learning about do...while loops,
I am getting a syntax error, not sure where it is though?
var secret = prompt("What is the secret password?");
do ( secret !== "sesame" ) {
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>
Shivam Kandwal
1,952 Pointswell that's work for me
3 Answers
KRIS NIKOLAISEN
54,972 PointsYou were closer the first time. From the link the syntax is:
do {
code block to be executed
}
while (condition);
So you'd have:
do {
secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
The other hint was to declare secret as "" outside the loop.
Shivam Kandwal
1,952 Pointshey this is my answer, we only need to call the secret variable inside the loop not to create a variable inside the loop.
var secret; do{ secret = prompt("What is the secret password?"); } while ( secret !== "sesame" ) document.write("You know the secret password. Welcome.");
So I just call the secret variable inside the do while loop and this work. That takes a long
Gareth Partridge
13,421 Pointsit is unfortunately still not working. I have tried to declare the secret outside the loop now in various ways.
KRIS NIKOLAISEN
54,972 PointsTake a look at this page
Some hints
- you have conditions to run in two locations
- declare secret outside the loop as ""
Gareth Partridge
13,421 PointsHi Kris Thanks for replying.
I am still struggling with a syntax error, I have tried so many different methods now, I feel like I am stuck in a loop. this is my latest.
var secret = prompt("What is the secret password?");
do "secret" ( !== "sesame"); {
secret = prompt("What is the secret password?");
while "secret" ( !== "sesame");
}
document.write("You know the secret password. Welcome.");
Shivam Kandwal
1,952 Pointshey this is my answer, we only need to call the secret variable inside the loop not to create a variable inside the loop.
var secret;
do{
secret = prompt("What is the secret password?");
}
while ( secret !== "sesame" )
document.write("You know the secret password. Welcome.");
So I just call the secret variable inside the do while loop and this work. That takes a long
Shivam Kandwal
1,952 PointsShivam Kandwal
1,952 Pointshey this is my answer, we only need to call the secret variable inside the loop not to create a variable inside the loop.
var secret; do{ secret = prompt("What is the secret password?"); } while ( secret !== "sesame" ) document.write("You know the secret password. Welcome.");
So I just call the secret variable inside the do while loop and this work. That takes a long