Dry penguins


#1

// the original Animal class and sayName method
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// define a Penguin class

function Penguin (name, numLegs) {
this.name = name;
this.numLegs = 2;
}
// set its prototype to be a new instance of Animal
Penguin.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};


#2

You don't seem to know what prototype does...

First, this is the structure of a prototype:

(variable).prototype = new (function)();

So, look at this:

That is a little big syntax error, for it doesn't really make sense. Why? Well, all you did was copy this:

Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

And change animal into penguin. Does NOT work. Also,

It says to put the parameter as only name.


#3

Hello,

Do you know why we can't use the extends keyword in this exercise?


#4

// the original Animal class and sayName method
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// define a Penguin class
Penguin.prototype = new Animal();
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

// set its prototype to be a new instance of Animal
Penguin.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};


#5

// the original Animal class and sayName method
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// define a Penguin class
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();
};