20. Penguins, Properties, and the Prototype


#1

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.prtotype = new Penguin();

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

var emperor = new Emperor("Genghis");

console.log(emperor.numLegs);

result :

Oops, try again. It looks like you didn't set Emperor to inherit from Penguin!

PLEASE Help!


#2

you misspelled prototype


#3

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

Error : Oops, try again. Make sure to log the number of legs emperor has!


#4

yep, many thanks!!!!!!!!!!!!!!!!!!!


#5

I'm having the same issue @lilliessiew is having. Exact code to the T. Any suggestions for receiving that error?


#6

this code(the one above) works for me. you can just delete it and paste it again.
Just in case:
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("Tito");
console.log(emperor.numLegs);


#7

Hey guys, I can't figure out what I'm doing wrong. Can anybody help? Here is my code... Thanks a lot!

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


#8

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