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?

Kevin Solon
Kevin Solon
256 Points

I thought I followed steps correctly but the webpage didn't load in the correct order?

I placed <script src="scripts.js"></script> right before the end of the </body> and it loaded the 2 pop up messages before the webpage content. wondering what I did wrong or if I did it wrong.

Shuchan Chen
Shuchan Chen
4,202 Points

I have the same problem. The two messages come up before the html. In the video, after the first message, it would load html. Then, show the second message. But it doesn't follow this order in my webpage. I'm using chrome.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>JavaScript Basics</title>
  <script>
    alert("Here's another message from Treehouse")
  </script>
 </head>
<body>
  <div class="container">
  <h1>Where to place your JavaScript code.</h1>
  </div>
  <script src="scripts.js"></script>

</body>
</html>

4 Answers

Steven Parker
Steven Parker
231,275 Points

Perhaps nothing is wrong.

It's not clear from your description, but perhaps the behavior you observed is correct for the program and browser. For a more detailed analysis, you would need to show the complete code and indicate what browser and version you are using.

Alexander Marciante
Alexander Marciante
Courses Plus Student 206 Points

Any help appreciated. I just started the course and can't believe I'm already stuck :( . I'm using Chrome Version 56.0.2924.87 on Win10

https://w.trhou.se/8vmsgevxf1

Loki Thor
Loki Thor
6,003 Points

I can't seem to emulate the same either. I would get two alerts and then it renders the page. Maybe modern browser just executes too fast that both alerts are called before the page renders? To be honest, it's not a big deal, but I do like the results in the video better: alert, renders HTML, alert.

Anna Kertesz
Anna Kertesz
5,380 Points

Having the same happen, on Chrome Version 58.0.3029.96 on MacBook Air.

My pop-up's look different too, but I assume that's because the browser has updated since the video was captured.

Below is the html used.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>JavaScript Basics</title>
  <script>
  alert("Here's another message from Treehouse");
  </script>
 </head>
<body>
  <div class="container">
  <h1>Where to place your JavaScript code.</h1>
  </div>
  <script src="scripts.js"></script>
</body>
</html>
Keegan Usher
Keegan Usher
26,226 Points

Try adding defer after the src, this might give you the results you are looking for. <script src="scripts.js" defer></scirpt>