16. (inheritance) console log/code works but failing to pass? Check your spelling!


#1

Running the code below is working - the output in the console is the penguin's name - but the codeacademy requirement is not passing?

Oops, try again. It looks like your Animal.prototype.sayName method does not properly log to the console 'Hi my name is [name]' where [name] is the name of the AnimalOops, try again. It looks like your Animal.prototype.sayName method does not properly log to the console 'Hi my name is [name]' where [name] is the name of the Animal

// create your Animal class here
function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
}


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    console.log("Hi may name is " + this.name);
}

I've also tried the following:

// create your Animal class here
function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
}


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    console.log("Hi may name is " + this["name"]);
}

This "works" but again getting the error message

Confused...


#2

Little typo here.
console.log("Hi may name is " + this["name"]);

"Hi may name is"


#3

haha yeh I just saw that! :slightly_smiling:
Thanks


#4

// create your Animal class here
var Animal = function(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}

This code works but no output unfortunately

// create the sayName method for Animal
Animal.prototype.sayName = function() {
console.log("Hi, my name is " + animal.name)
}

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();