Dealing With the Keyboard

With our triangle drawn, our next job is to deal with the keyboard. This involves the following steps:

  1. Listening for the events your keyboard fires
  2. Inside the event handler, accessing the KeyboardEvent's keyCode property.

Handling the cases when the left, right, up, and down arrow keys are pressed. There are several ways of doing this, but we are going to use a familiar (but less-than-ideal approach). Go ahead and add the following lines of code just above where you defined your drawTriangle function:

Get hands-on with 1200+ tech skills courses.