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 Introducing JavaScript Finishing the Game Adding New Graphics

Ricardo Guerrero
Ricardo Guerrero
4,424 Points

How does the 'game.js' file knows to refer to the 'phaser.js' library, while calling any of its functions or methods?

-Thank you in advance

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

There are actually a couple different ways to do this in JavaScript, so the explanation can vary. But since this is an Intro course you'll probably notice in your HTML file there are <script> tags to load the JavaScript and the phaser.js file is loaded before the game.js file. The phaser.js file will create a variable or function called Phaser that can be used by later files to access the library. (This is not automatic. Loading game.js won't create Game unless it's explicitly written to do so.)

Joseph Groark
Joseph Groark
24,499 Points

In the HTML file that you will be working add the corresponding Javascript file you want to work with (in this case phaser.js)...

By simply writing in the <script> tags (<script src="phaser.js"></script>) to the body section of the HTML it will allow use of the the functions in the Javascript file you have linked.