20/30 Penguins, Properties,and the Prototype


I can not figure out what I am doing wrong with this code!

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

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

Emperor.prototype = new Penguin();

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

var emperor = new Emperor("Alvin");


The error I get is "ReferenceError: Emperor is not defined"


In your opinion, should Emperor be defined in your code?

And then consider whether you have done that. Where?

You might want to have a look at the examples for what to do with prototypes as well, I can't explain it because I have no clue myself, but what you wrote there doesn't add up! new Penguin() creates an instance of Penguin, right? Should a prototype be an instance of some other class? Doesn't sound right to me, it's a penguin, not a prototype! You should probably be creating a class and then copying over the prototype, that's about as much as I've understood.

(I may or may not be attempting to learning JS by answering questions about JS before knowing JS)


Egads! I figured it out. It's not enough to define Emperor as a new Penguin -- I need to first create a function called Emperor that takes "name" as its parameter. I was thinking declaring Emperor as a new Penguin was enough, but that's not the way it works.

Thanks, jonatan!