JavaScript implementation of Snake