Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Commands, or functions, are the basic building blocks of a program. A function lets you define specific steps a computer should take. You then make the computer perform those steps by "calling" the function. Learn about functions while adding to a JavaScript game.
Using Functions
-
Create or "declare" a function. This stores the steps of the function in memory. The function doesn't activate, but the computer remembers what to do:
function add(x, y) { alert( x + y); }
-
"Call" a function. Make the function do something by calling it by name and giving it some information:
This will make an alert box open in your browser with the number 5 in it.add(2, 3);
Downloading and Running the Project Files
Because of how the Phaser.JS library handles files, you need to be running a web server locally to view a working copy of this project. You can't just open the index.html file in your web browser as you might a basic HTML page. There are several simple ways to get a web server up and running on your computer:
- The Web Server for Chrome is an easy-to-install extension for Chrome that lets you select a folder on your computer (like the folder with the game files in them) and deliver them through a basic web server. This is probably the easiest way to get started — but you'll need to use the Chrome web browser.
- If you don't want to use Chrome, check out a simple guide for getting a local web server set up for several other methods.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Mykela Brown
522 PointsHello, I have been trying to add more coins and more platforms. So far I have been able to make 7 coins and 6 platforms.
Posted by Mykela BrownMykela Brown
522 Points1 Answer
-
Silvia Ramos
Front End Web Development Techdegree Graduate 18,318 Points1 Answer
-
Gerald Susanteo
Front End Web Development Techdegree Student 7,117 Points1 Answer
-
Masud Rana
2,865 Points1 Answer
-
Steven Mount
Full Stack JavaScript Techdegree Student 1,520 Points1 Answer
-
Bozena Jablonski
4,944 Points2 Answers
-
Brittany Kendrick
3,909 Points1 Answer
-
arielp
3,516 Points2 Answers
-
Jr A
625 Points1 Answer
-
Ashley Fleming
381 Pointscoin Collector is not working, it comes in a black screen
Posted by Ashley FlemingAshley Fleming
381 Points1 Answer
-
Martin Guzman
2,863 PointsProblems with the Video Game - player can't turn right
Posted by Martin GuzmanMartin Guzman
2,863 Points1 Answer
-
Aaron Thesing
233 Points2 Answers
-
kristianburrows
2,283 Points1 Answer
-
Mapalo Mwaba
Full Stack JavaScript Techdegree Student 771 Points2 Answers
-
Tristan Gregory
104 Points2 Answers
-
Przemyslaw Chmiel
13,532 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up