Here is a little game done with JavaScript. Take a look into the code to see more how it is programmed.
A = Player
o = Coin
Use arrow keys to move around