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 A Closer Look At Loop Conditions

Nick Casey
Nick Casey
1,840 Points

Ha, so I may be a little off here....

I'm trying to structure the following .js file as a loop that allows a user to input the answer "sesame" before receiving a successful return prompt.

app.js
var secret = prompt("What is the secret password?");
varCount +=1;
if (parseInt(guess) = "sesame") {
  correctGuess = true;
}
 while (! correctGuess )
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="app.js"></script>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
228,978 Points

Looks like you have several good learning opportunities here! Here are a few hints:

  • you'll need braces to enclose your loop block
  • for this particular challenge, they don't want a "do" loop - you'll have to check your condition first
  • parseInt is for converting to numbers, you won't need it because this will be a string comparison
  • you declared a variable varCount but you don't use it (and you won't need it)
  • you reference a variable guess that was never declared (did you mean secret, which holds the user reply?)
  • you didn't declare correctGuess before assigning it, and you might want to do that before the loop

See if you can get it with these hints, or see if you can get closer and ask again.