19. Black (and White) Penguin Magic


#1



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


The Error Message says
"Oops, try again. Make sure you create a new instance of Penguin called penguin. Your code threw the following error: ReferenceError: penguin is not defined"

It does console.log 'Hi my name is tux' just fine so I don't know what the problem is.


// 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 = new Penguin("tux");
Penguin.sayName();

#2

Hi your instance should be call

var penguin = new...

Instead of

var Penguin = new ..

It should be with The downcase p


#3

This Editor is quite sensitive , so you should pay attention whether you write it Uppercase or Lower one.

Good luck !
You are doing good.


#4

it says i've passed but nothing was logged to the screen and when i checked my penguin doesn't have the method sayName. no error comes up but also doesn't look like it's inherited??? anyone have any ideas?

// 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();
penguin = new Penguin("BoB");
penguin.sayName;
console.log(penguin.hasOwnProperty('sayName'));

#5

next exercise used similar method and worked fine. odd.