Marching Penguins


#1

Hello,

I'm getting a Syntax error, missing " ) " after function body.Can anyone see what I'm missing?

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, sayName){
this.name = name;
this.numLegs = numLegs;

// create a sayName method for Penguins here
var sayName = function(){
console.log("Hi my name is " + this.name);
};
// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();


#2

...Also just tried this in place, trying to create a sayName method for penguin. Same error.

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


#3

Try removing the sayName parameter from the Penguin constructor. sayName is a constructor, so having it as a parameter might be messing things up a bit. Otherwise it looks good to me!


#4

edit: sayName is to be used as a method not a constructor.


#5

this worked for me

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();