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

My code is working in a workspace just fine with no errors, but the challenge task window returns a parse error?

I'm sure it is something small, but my eyes aren't really helping me out here. Again, when I run the code in a workspace it works flawlessly, but for some reason I cannot proceed past this task because when I copy the code in (exactly as it is in the workspace) I get a parse error. Really wish it would at least tell me what line the error was on.

Any ideas?

script.js
let secret;
do {
   secret = prompt("What is the secret password?");
} while ( secret !== "sesame") {
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>

2 Answers

Let: is used to declare a block scope variable. this mean that if you declared the secret variable outside your (do while loop) it is likely not to be accessible within the loop. https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Sentencias/let. Keep Coding!

Ah! I see, thank you for clarifying!

Welp. I got it to work by changing "let" to "var." Wild. Anyone else come across this issue before? Seems like it should work either way, though I do notice the challenges seem to be very strict on syntax.

This is made even more confusing considering that at the beginning of this course, I was urged to continue using let and const over var. Look how far that got me :p

No shade to Treehouse, I am loving the course so far.