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

Kianna Aether
Kianna Aether
2,390 Points

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

Oliver Duran
Oliver Duran
11,726 Points

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!

Kianna Aether
Kianna Aether
2,390 Points

Ah! I see, thank you for clarifying!

Kianna Aether
Kianna Aether
2,390 Points

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.