Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, December 6, 2012

Codecademy: Codeyear Adding it Up


//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


This is an example of scrolling text using Javascript.

Popular Posts