Adjusting the Position

It is time to tie together the triangle we’ve drawn with the code we just added for dealing with the arrow keys. What we are going to do is define two counter variables called deltaX and deltaY. What these variables will do is keep a count of how far to move our triangle as a result of arrow key presses. This may sound a bit confusing right now, but hang on tight!

First, let’s go ahead and define our deltaX and deltaY variables and put them to use inside our moveSomething function. Add lines 1-2, 7, 10, 13 and 16 to your code:

Get hands-on with 1200+ tech skills courses.