Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.