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?

Location Location Location...

So... I followed the instructions... and my page content still loads first... and i refreshed the page.. went to google and came back.. WELP!! Not sure what to do, but this class is AWESOME!!


5,590 Points

I forked the workspace and it worked perfectly for me. Is there any chance you have javascript turned off for it? Like through a extension like noscript or something like that.

I'm not sure.. because I see all the popup boxes just fine, they just didn't come in the order they were supposed to..

5,590 Points

I'm not 100% sure if I'm addressing it right though, because the way you are wording it isn't saying which order you are expecting it to come up first. But if the workspace isn't wonky for you atm:

Whichever one is first in the html should be the one that pops up first. So 'still here yo' should pop up first, and then 'hey you're back for more' should pop up second because the linked file was placed second in the html.

1 Answer

Since you are referencing the external "scripts.js" file right at the bottom of your HTML document, your order of execution would be as follows:

  • Internal JavaScript executes first outputting: "Still HERE YO!!!"
  • Your HTML body loads up next outputting: "Where to place your JavaScript code."
  • Your external "scripts.js" is then executed outputting: "Hey, You're back for more?"

The reason why we reference the external JS file right at the bottom of the HTML document is because;

  • JavaScript is almost always used for user interaction/behavior on the webpage so it makes sense to have the page's content loaded fully before making any manipulations with your JS script.

I hope this helps. Cheers!