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 trialAlexander Yamunaque
3,919 PointsThe code doesn't respect the order of JavaScript like the video
This code does not show the correct order like the video in JavaScript Basics.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Basics</title>
<link href="css/style.css" rel="stylesheet">
<script>
alert("Another message inside index.html")
</script>
</head>
<body>
<main>
<h1>Hello, JavaScript!</h1>
</main>
<script src="js/script.js"></script>
</body>
</html>
The video shows first the first alert of Javascript inside <head>, then shows the <h1> element and finally the last JavaScript script.
But, when I execute my code in HTML first appears both alerts and finally the <h1> element.
Why does it happen?
2 Answers
Steven Parker
231,153 PointsStandard modern browser behavior is to run all scripts before rendering and displaying the page.
Older browsers (like when the video was made) behaved differently.
Alexander Yamunaque
3,919 PointsThank you Steven!