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.
Today's episode, on YouTube
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.
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.
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.
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.