20. Penguins, Properties, and the Prototype


#1


Hello,
Do you have any idea how to get out of this?
It seems nothing is printed when I type console.log and the following error appears "Oops, try again.
Make sure to log the number of legs emperor has! "
I have tried all the tricks some of you proposed on related topics, I have entered the code, copy, refresh the browser, but none of them works.

I would really apppreciate your help :slight_smile:


function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

// create your Emperor class here and make it inherit from Penguin
function Emperor(name) {
this.name = name;
}
Emperor.prototype = new Penguin();
// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("Miko");
console.log(emperor.numLegs);


#3

Looks like if you take out the argument "miko" it will work. I have no idea why :slight_smile: .


#4

Now the same code simply works. Thanks :slight_smile:


#5

It says make sure to properly define the Emperor cosntructor
Could you be so kind and explain why does not work?
Thanks in advance

function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

// create your Emperor class here and make it inherit from Penguin
function Emperor (name) {
this.name=name;
}

Emperor.prototype= new Penguin ();

var Emperor= new Emperor ;
console.log(Emperor.numlegs);


#6

It should work all good now :slight_smile:

function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

// create your Emperor class here and make it inherit from Penguin
function Emperor(name) {
this.name = name;
}

Emperor.prototype = new Penguin();
// var name should be lowercase and new Emperor should have a penguin's
// name inside the brackets, like this:
var emperor= new Emperor("XX");

// lowercase in emperor and the parameter's name is: numLegs
console.log(emperor.numLegs);


#7

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