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

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.