//sample solution
//adding methods and properties to a class after inheritance
function Car( listedPrice ) {
var price = listedPrice;
this.speed = 0;
this.numWheels = 4;
this.getPrice = function() {
return price;
};
}
Car.prototype.accelerate = function() {
this.speed += 10;
};
function ElectricCar( listedPrice ) {
// add an 'electricity' property to this class
this.electricity = 100;
var price = listedPrice;
}
ElectricCar.prototype = new Car();
// Add refuel method here:
ElectricCar.prototype.refuel = function(numHours) {
this.electricity += (5*numHours);
};
myElectricCar = new ElectricCar(500);
myElectricCar.refuel(10);
console.log(myElectricCar.electricity);
No comments:
Post a Comment