I am trying to create a simple animation that makes a car image most across the screen (learning exercise). I am trying to make it happen with setInterval, and this doesn't seem to be working. The image is stationary. See code below:
var Car = function(x, y) {
this.x = x;
this.y = y;
};
Car.prototype.draw = function() {
var carHtml = '<img src="http://nostarch.com/images/car.png">';
Car.prototype.moveRight = function(distance) {
this.x;
this.carElement.css({
left: distance,
top: this.y
});
};
var tesla = new Car(20, 20);
tesla.draw();
function runOnInterval(fn, arg) {
setInterval(function () {
fn(arg);
}, 1000);
}
runOnInterval(tesla.moveRight(), 10);
As I said, this results in the image being stationary, and an error message in the console saying "fn is not a function". Can anyone tell me what I am missing here? Thank you.