Week 9 - Task 2c

Moving the "pixel"

Lets add some stuff to 2b

This is the final part.
Lets make code so that pressing left/right arrows move the pixel!

Javascript

1. Add the event listener onkeyup to the body of the document.

Hint: Use the build-in reference to the body element: document.body

2. Add two conditions.

Hint: What does "moving a pixel" really mean? Think of it as removing the black color of current "pixel" and adding the black color to the next. You might want to make a function for each.

Hint: Use console.log(event.key) to get the name of the arrow keys (which you must use in the conditions)

3. Add special conditions for when we are moving out of boundary.

Example of how it might look like