19. Black and White Penguin Magic


#1


https://www.codecademy.com/en/courses/objects-ii/3/4?curriculum_id=506324b3a7dffd00020bf661#


ReferenceError: Penguin is not defined


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

function Penguin(name) {
    this.name = name;
    this.numLegs = 2
}
Penguin.prototype = new Animal();
var Penguin = new Penguin("Zain");
penguin.sayName( );


#2

Hi this line

var Penguin = new Penguin("Zain");

this part

var Penguin ..

you wrote Penguin instead of penguin should be with the downcase p


#3

I'm having the same problem, however I get the error message "TypeError: penguin.sayName is not a function"


#4

HI can you post your 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
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

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

var penguin = new Penguin("Jerry");
penguin.sayName();


#6

HI this line

Penguin.prototype.sayName = new Animal()

you should remove the sayNAme so it should be like that

Penguin.prototype = new Animal()

#7

ok thanks, sorry didn't pay attention to your other response


#8

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