17/30 I don't know what's wrong?


#1

If I start my code, it logs "Hello, my name is Captain Cook" to the console, but I get the following error message:

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

Here is my code:

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() {
console.log("Hello, my name is " + this.name);
}
// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();

I really don't know what's wrong with it. I've looked up the three other posts related to this particular lesson and it didn't help.

And I've tried writing the penguin-method with a semicolon at the end like this, as suggested to another user in one of the other posts:

Penguin.prototype.sayName = function() {
console.log("Hello, my name is " + this.name);
};

I've then run the code again and it didn't work for me. Does anyone know what's wrong? Please help!


#2

I've figured it out now. It's the output in console.log.
For anyone who has the same problem:

You MUST write it like this:

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

It's the lesson checker who thinks that you're wrong otherwise.


#3

I was about to lose my mind. Thank you for the heads-up!


#4

THANK YOU SO MUCH! I really despise the lack of HELPFUL error messages in Codecademy's lessons.


#5

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() {
console.log("Hi my name is " + this.name);
};

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

just in case a person doesn't understand here and u can copy and paste if u want