The Mystery of the Penguins, the Properties, and the Prototype


#1

As you may as well know, number 20 isn't working correctly. It starts out like this...

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

// create your Emperor class here and make it inherit from Penguin


// create an "emperor" object and print the number of legs it has

For example,

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("Mr. Emperor Penguino");
console.log(emperor.numLegs);

and all of its derivatives fail to work.

And you, leonhard.wettengmx.n, stay out of this! I blame it on you even though it most likely isn't, mainly because you try to give guidance rather than answers!


#2

@455nefer

Hi,

If your emperor inherits from Penguin class, it should have legs right?
Here, your numLegs will be undefined because it isn't put in parameter like this:

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

Hope this helped you! :slight_smile:

P.-S.

This forum is dedicated on helping other one by making them understand their errors so they don't repeat it afterwards. We don't give directly answer to people because this is cheating. We must be sure that the person understands what's he's doing wrong.


#3

Well, not according to my teacher, nor my dad. They are of the opinion that it's constructive learning.

And thank you for figuring that one out! I give you my thanks.


#4

Well said.

These forums are definitely not for answers.
They are meant for guidance. Even if leonhards guidance is slightly longer than other people's he is giving guidance like these forums are meant to, and we would appreciate it if you were not hostile towards other users.

Thanks,
Alex