Marching Penguins


#1


https://www.codecademy.com/en/courses/objects-ii/3/2?curriculum_id=506324b3a7dffd00020bf661#


My code returns "unexpected token {" but I don't know where I have an extra "{"? Any help would be appreciated!


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
var Penguin = new Animal(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();


#2

// create a Penguin constructor here
var Penguin = new Animal(name, numLegs) { // you created new object
    this.name = name;
    this.numLegs = numLegs;
};

Problem is that you need create a Penguin constructor:

function Penguin(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;    
};

var Penguin = new Animal(name, numLegs); // it means that you created new object using Animal constructor

#3

I tried that and it worked! Thank you!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.