Please enable JavaScript to use CodeHS

Chapter 3

Animation and Games

3.4 Key Events

Key Event Methods

Using Key Events

Detecting a Specific Key

Press the Left Key

Keyboard Square

Check Your Understanding

  1. Incorrect Correct No Answer was selected Invalid Answer

Exercise: Basic Snake

Vocabulary

Term Definition
Constant A variable in a program that has a value that does not change.
Magic Number A number in your code that appears arbitrary. These should all be replaced with calculations or constants.
Canvas The screen in which our graphics programs are drawn.
Scope In what part of the program the variable exits
Global variable A variable that can be used throughout a program, in every scope
Event An event is an action (such as clicking the mouse or pressing a key on the keyboard) that a program detects and uses as input.
Coordinate system A coordinate system uses numbers as coordinates to place objects in a geometric space.
Callback Function A function passed as a parameter to another function in order to be called later.