Marching penguins


#1

what am i missing here i get the message unexpected token {

any ideas?

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
function Penguin(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;    
}

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

well, you have a problem here:

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

this looks like a mix between creating an instance of an object and a object constructor, look at the comment, which of the two you need? A Penguin constructor, with other words an object constructor, now look at your Animal/object constructor:

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

do they look similar to you? Both are object constructors, so the syntax should be pretty similar right?

oh, and don't forgot that a opening curly bracket ({) requires a matching closing curly bracket (})

If you have more problems, post an updated version of your code


#3

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