DRY Penguins (Needs Debug)


#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
Penguin.prototype.Animal = function(numLegs){
    this.numLegs = 2;
};

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


#2

Not sure what the goal of this code is. You are supposed to make a penguin constructor just like the previous exercise. Remove the above code and make a simple function function Penguin(name) { then set name to name and numLegs to 2.


#3

Oops, try again. Make sure you properly define the Penguin constructor
ReferenceError: Can't find variable: Penguin


#4

Let me know your updated code?


#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
Penguin.prototype.Animal = function(name){
this.name= name;
this.numLegs = 2;
};

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


#6

Like I said this should be removed and replaced with function Penguin(name) {?


#7

Oops! I misunderstood your pointer. Sorry!


#8

// 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();

var penguin = ("Richard Parker");

penguin.sayName();

How would I get this to say it's name?
(This is the next lesson)


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.