In the following code, I am having trouble figuring out how to log (in the console) the name and numLegs properties of Penguin (i.e., "emperor" and 2), without changing the inside of the function?
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}
var emperor = new Penguin("emperor");
How can I do that?
Simply accessing it's properties. Your emperor is an object, which means that you can access properties with . syntax.
function Penguin(name){
this.name=name;
this.numLegs=2;
}
var emperor = new Penguin("emperor");
console.log(emperor.name);
console.log(emperor.numLegs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With