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 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
216,135 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.