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

Thursday, December 6, 2012

Codecademy: Codeyear Inheriting Data


//sample solution


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 ) {
   var price = listedPrice;
}
ElectricCar.prototype = new Car();

myElectricCar = new ElectricCar(500);

console.log("myElectricCar has speed " + myElectricCar.speed);//0

// Print out myElectricCar's number of wheels
console.log("myElectricCar has numWheels " + myElectricCar.numWheels);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts