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 Exit Out of the Loop – One Solution

Amy Preci
Amy Preci
6,247 Points

Guessing game

How would you get a message to display in the HTML after each guess that says "You have X tries left" It did not work after I tried to reassign "message" variable after the prompt. Wondering how that would work with a loop. I was able to display that information in the prompt, but not on the HTML page. Wondering if anyone has done this. Thanks.

josephweiss2
josephweiss2
7,094 Points

can you share your code here? it will make it easier to get the problem solved

1 Answer

Steven Parker
Steven Parker
231,248 Points

Modern browsers don't render the page until the JavaScript program is completely finished. For this reason, mixing interaction using "prompt" with page updates won't work. So when using "prompt", the outputs should be done using "alert" or other "prompt" messages.

Interactions using the page are done with forms or the event mechanisms, both of which will be covered in later courses.