Penguins, Properties, and the Prototype


Create an Emperor class that takes a single name parameter and sets its name property to be this value. Don't set a numLegs property in the constructor.

Similar to what we did in the previous exercise, make Emperor inherit from Penguin by setting the prototype of Emperor to be Penguin.

Create a new emperor object that is an instance of the Emperor class with any name you'd like. Then use console.log to print the number of legs emperor has—this should have been inherited from Penguin!
What did I do wrong?

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

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

Emperor.prototype = new Penguin();

// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("George");



Your code works for me, it logs 2.

What did the error write?


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