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 Practice Object Interaction Starting with Some Methods Demo: Add Patrons and Books to the Library Class

Joe Elliot
Joe Elliot
5,330 Points

Interesting fault when my HTML script tags were in the wrong order. Why is this?

So I'm using VS Code editor as I code along with this class. My push method kept returning "Patron is undefined". I eventually figured out it's because in my HTML, the the <script src> tag to my "Library" File was ABOVE the <script src> tag to my Book/Patron files. Moving the library <script> tag to the bottom solved this.

So, it seems the order you list your HTML links to your JS files is important. I was previously unaware of this. Is there a simple logic to this order? Is it something a developer knows in advance?

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Joe Elliot,

That's correct! The HTML file is being read from top to bottom so the order of importing your files does matter. If one piece of code depends on another file to run you'll want to make sure to add those script tags in the right order 🙂

Joe Elliot
Joe Elliot
5,330 Points

Thanks Ronald, I guess it makes sense that the Books and Patrons have to be populated in this example, before a library can be created for them.

Thanks again!