Section 17


#1


Replace this line with your code.

function Animal(name, numLegs) { // THis is a constructor
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
var Penguin.prototype.syaName = function() {
console.log("Hi my name is " + this.name);
};

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


#2

this line:

var Penguin.prototype.syaName = function()

why use a var (variable) keyword? You create a method, not a variable.

You also misspelled sayName on this line


#3

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