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 trialMichael Loschiavo
7,267 PointsIs there a Treehouse lesson which explains the importance of script order?
As I was working on this project, I kept running into the error of my elements displaying as "undefined" both in my console and on the index.html file. I started the JS path with OOP since this is where I needed to improve. I love how Treehouse breaks down concepts, was there an earlier video I had missed which discussed this? Thank you.
2 Answers
Shawn Denham
Python Development Techdegree Student 17,801 PointsYes in the JS basic course they go over script order. The where, when why kind of thing of where you place your script tags in your HTML and what effect it will have.
If you can post your HTML I might be able to help you with it if you like.
I should add..
Where you place your script would be entirely dependent on what that piece of script is doing. I usually place all of my scripts just before the closing body tag since I am usually trying to manipulate something in the DOM with it. I can't replace the text in an H1 tag if that tag hasn't even rendered yet! I am assuming that you have your JS script in the head of your document based on the errors your getting.
anyhow, like I said before I am more than happy to go over your HTML and your script placement if you like!
Happy coding!
Shawn Denham
Python Development Techdegree Student 17,801 PointsCan you fork your workspace and send me a link so I can play in it to see what happening?
Michael Loschiavo
7,267 PointsYes, here is my workspace: https://teamtreehouse.com/workspaces/14610392
Michael Loschiavo
7,267 PointsMichael Loschiavo
7,267 PointsThanks for the reply Shawn! I'll have to go back and check out the earlier lesson. For this exercise, I was given a pre-written index.html file with the scripts placed above the closing body tag, I've attached the code below. In this workspace, I was trying to figure out which files to place certain code to make my application work. I know that, depending on the order, some script files can reference others and whatnot. I was getting the errors I stated, so I switched around the code locations in each JS file to other JS files to debug. I believe app.js has access to all the previous scripts, right?