17/30: What is wrong with this code?


#1

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// create a Penguin constructor here
function Penguin(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}

// create a sayName method for Penguins here
Penguin.prototype.sayName = function() {
return("Hi, my name is " + this.name);
};

// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();

I get an error from this code that says the following:
Oops, try again. It looks like your Penguin.prototype.sayName method doesn't return 'Hi my name is [name]' where [name] is the penguin's name


#2

Try to use console.log(); instead of return in method.
It worked for me.