Challenge for Object Functions, Constructors and Prototypes

Challenge

What will the following code print?

//create car object
var car = {
    speed: 0,
    increaseSpeed: function(){
        this.speed += 5;
    }
};

//two attempts to increase the car's speed.

var increaseSpeed = car.increaseSpeed;
increaseSpeed();

var accelerate = function(amount){
    this.speed += amount;
}
car.accelerate = accelerate;
car.accelerate(8);

console.log(car.speed);

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]