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

Why do I have to repeat the content of secret?

Why can't I run secret inside of the while loop? Why do I have to repeat myself inside and outside the loop: secret = prompt("What is the secret password?")

1 Answer

Jeremy Hamilton
Jeremy Hamilton
7,229 Points

I assume you were simply on the while loop exercise, and that's how you'd run it inside the while loop since the loop doesn't run until you've met a value. When you move onto the do...while loop, then you'll get to a situation like the one you want more, a loop that runs at least once, so you can put the first question inside of the loop.