Black (and White) Penguin Magic


#1


keeps saying
Oops, try again. Your code threw the following error: TypeError: Right-hand side of 'instanceof' is not callable
please 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
function Penguin (name,numLegs) {
    this.name = name;
    this.numLegs = 2
    
    }

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

var Penguin = new Penguin ();
var pete = new Penguin ("Bird 1");
penguin.sayName( );


#2

var Penguin = new Penguin (); // you haven't constructot Penguin()
var pete = new Penguin ("Bird 1");
penguin.sayName( ); // penguin is undefined

Try this:

var pete = new Penguin ("Bird 1");
pete.sayName();

#3

it should like this
var penguin =new Penguin;
the "P" in the first one should be small
and you should delete pete object


#4

But it's wrong!! Should be:

var penguin = new Penguin ("Bird 1");

the "P" in the first one should be small

As a rule, variables begins with small letter. But variables can be with uppercase first letter.

and you should delete pete object

var penguin = new Penguin ("Bird 1");
penguin.sayName();

var pete = new Penguin ("Bird 2");
pete.sayName();

Both are correct!!


#5

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