DRY Penguins


#1

hey!! What's wrong in my code??
I'm getting this error: Oops, try again. The Penguin constructor should always set this.numLegs to 2. The constructor should only take a single parameter!

// 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 Animal( name ) {
this.name = name;
this.numLegs = 2;
}
// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();


#2

You were asked to define a Penguin class, but you decided to just redefine Animal class here:

// define a Penguin class
function Animal( name ) { // <-- this is new definition of Animal class
    this.name = name;
    this.numLegs = 2;
}

#3

yea yea I got it..
thanku..
:slight_smile:


#4

You're very welcome :slight_smile:


#5

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