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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

Brooke Guy
Brooke Guy
8,179 Points

There was an error with your code: SyntaxError: Parse error

This is the error I am getting: There was an error with your code: SyntaxError: Parse error

script.js
var secret = prompt("What is the secret password?");
while ( secret !== "sesame" ) {
  do (secret = prompt("What is the secret password?"));    
}
document.write("You know the secret password. Welcome.");
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

Aren't you supposed to write a:

do {

}while()

loop?

if that's the case you need to change the order of do and while.
you can change the do-while for a simple while it's not neccessary there and try to use console.log() for printing results in the console (in browser press "crtl + shift + I => console panel)

var secret = prompt("What is the secret password?")
while(secret !== "sesame") {
    secret = prompt("Wrong password, try again!")
}
console.log("password accepted").

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi Brooke, you're on the right track, however a do while loop is written in the following way:

do {
  console.log("i'm doing this");
} while (a !== b)

Also you don't need to declare your secret var twice, just once before the do while loop :)

Hope that helps!!