20. Penguins, Properties, and the Prototype


#1

Hi,

I'm pretty confident my code is correct, although I can't seem to pass submission.
I keep getting for following error:


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

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

#2

Capitalization is key.

var emperor = new Emperor("Bob");
Should be :
var Emperor = new Emperor("Bob");


#3

I have the same code and same error as above. Capitalizing the var name doesn't solve the issue. It throws a different error, "Oops, try again. Make sure to properly define the Emperor constructor!"

In the instructions and in the hint, it says to define your Emperor object as lowercase "emperor".

Why would capitalizing the variable name make a difference in this case? Wouldn't it just confuse your new instance/object, "Emperor", of the Emperor class with the Class itself, "Emperor". Variable names should be specific and unique.


#4

There must have been a bug, because it seems to work perfectly with my original code now. using lowerCase.


#5

Yeah, it seemed to work but wouldn't accept it unless it looked like this.

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

#6

It says lowercase, assume it's lying. :wink:


#7

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