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 trialHyeri Chung
2,178 PointsI can't understand what the question wants me to do anymore.
I think this code works for the asked query but I can't meet the expected answer to this question. will be appreciated if you can have a look for my code. what should I change for the answer? is it necessary to follow the question answer's instruction?
var password = 'sesame' var correctanswer = false;
do { var secret = prompt('what is the secret password?'); if ( secret === password ) { correctanswer = true; document.write('you guessed the right password. :p'); } } while ( ! correctanswer )
var password = 'sesame'
var correctanswer = false;
do {
var secret = prompt('what is the secret password?');
if ( secret === password ) {
correctanswer = true;
document.write('you guessed the right password. :p');
}
} while ( ! correctanswer )
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Steven Parker
231,275 PointsFor best results, always follow the challenge instructions and do exactly what they ask for and nothing extra.
Here's a few hints for this one:
- you only need to call the "prompt" method once, and only inside the loop
- declare (but don't assign) the "secret" variable before the loop
- the inner body of the loop should stay the same
- the line after the loop should stay the same