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 JavaScript Basics (Retired) Introducing JavaScript Where Does JavaScript Go?

I can see my body of the page before my alert messages come up

Why am i seeing my alert pop up after my webpage is displayed?

2 Answers

Hey Marlon,

If your script tag is placed towards the end of your document, such as above the closing body tag, the main content of your site (HTML/CSS) will load before your script runs.

It is on the <body> that means shouldnt the second alert come on after the webpage loads up?

Matthew Francis
Matthew Francis
6,967 Points

It's because you put your Javascript above your HTML code. Thus, your javascript will be executed first and this is bad practice. Always put your javascript below as when you try to add listeners,etc, things will go bad quite quickly.