# Game Coder Episode 002

Start-off with a review of last weeks homework, then we start writing javascript this week.

We introduce functions. We write functions of our own, plus we use functions that the web browser provides for us.

We show one of the ways to tell the browser to execute our code once our web page has loaded.

We introduce variables to hold values that we will manipulate in our code.

We use JavaScript to change the position of the items we put on screen last week.

# Homework Review

Review of the homework from Episode 001

What are hexadecimal numbers? Think of numbers that go from zero to fifteen, rather than zero to nine.

Humans think of numbers in 0, 10, 100 columns because we have ten fingers. Computers don't need to stop at ten, because they don't have fingers! Computers do all their counting in twos "on" or "off", also called binary. Binary numbers are difficult to write, because they take up a lot of space. As a compromise, to make life easier for humans to share numbers with computers, we group binary numbers in sets of 4. This gives us sixteen combinations for every set of four, which is where hexadecimal comes from. It's convenient for humans to read hexadecimal, because it looks kind of like decimal.

00000000000
10100000001
20200000010
30300000011
40400000100
50500000101
60600000110
70700000111
80800001000
90900001001
100A00001010
110B00001011
120C00001100
130D00001101
140E00001110
150F00001111
161000010000
...
201400010100
...
322000100000
...
1288010000000
...
255FF11111111

## Color Codes

Color codes represent the amount of red, green and blue used to make-up a color. Colors codes are usually a single hexadecimal character for each color (for example, #2bb), for a range of 0...15 for each of red, green, blue. Alternatively color codes can use two hexacecimal characters (for example, #ff00ff) to give a range for each color of 0...255.

# Lesson Details

## Key Concepts

• functions
• variables
• using built-in javascript functions
• using setTimeout() as a way to call our code
• conditional
• comparing variables to values
• the if statement
• using > (greater than)

## Functions

A function definition gives JavaScript a bunch of instructions that we want all executing together. We will see how to define a function this week, and look at a couple of the ways we use to tell the browser how to execute the function.

We use the built-in browser function setTimeout to call one own code every quarter of a second (or 250 milliseconds). This will be our application's control loop.

We use the built-in browser function document.getElementById(), to find things on screen, then move them around.

# Homework

## Conditionals

Look at other conditionals (<, ==, <=, >=)

Change the code to make the player go the other way. You will need to use a different conditional to check when he reaches the side of the screen.