19. Black (and White) penguin Magic Problems [SOLVED]


#1

This code gives me the error:
Oops, try again. Make sure to create a new Penguin instance called penguin!
It's probably something obvious, can anyone help???

// 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
var Penguin = function(name, numLegs) {
    this.name = name;
    this.numLegs = 2;
};
    Penguin.prototype = new Animal();
    
    var penguin = new Penguin(); {
        this.name = "IsTheLittlePenguin";
    }
    
    penguin.sayName();

#2

Penguin.prototype = new Animal();
var penguin = new Penguin(name);
this.name = "penguin";

some kind of fault in syntax you have...
var penguin = new Penguin(); {
this.name = "IsTheLittlePenguin";
} Semicolon after new Penguin() seems unnecessary...also there is no a variable name


#3

Everything is alright except this:

 var penguin = new Penguin(); {
        this.name = "IsTheLittlePenguin";
    }

Since Penguin is already a function, you can just put the name inside, like so:
var penguin = new Penguin("InsertNameHere");


#4

If I'm not wrong, name is a valid variable because it inherits the properties from the prototype Animal.


#5

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