20/30 I don't see the problem?


#1

I receive the error message 'Oops, try again. It looks like your Emperor constructor does not properly save the name passed to it!' but I can't see a reason why it shouldn't be saving?

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 = Penguin;

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

var emperor = new Emperor("Flippers");
console.log(emperor.numLegs);


#2

@joshlepine,
You will have to change your

Emperor.prototype = Penguin;

into

Emperor.prototype = new Penguin();

#3

@joshlepine,

J a v a S c r i p t and it's == p r o t o t y p e - C h a i n ==

They want you to set up the chain:

        OBJECT
  Object.prototype
           ^
           |
  Animal.prototype  (( has the sayName Method))
           |                              ^
           |                              | 
           |                    Animal Class-Constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Animal
           |
           |    <<== You define this link in the Chain using
           ^            Penguin.prototype = new Animal();
           |
  Penguin.prototype ((is empty))
           |               ^
           |               | 
           |          Penguin Class-constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Penguin
   /Instance /      <---   using new Penguin("aName");
   | of      |
   | Penguin |
    The Penguin-Instance has access
     to Animal.prototype.sayName Method
     via the Penguin-prototype which is
      -chained- to the Animal-prototype.

#4

Thank you! I was focussing too much on trying to work out what was wrong with the name parameter that I didn't notice that!


Short-Term Memory Syntax Error