24. Constructors With Methods


#1

function Rectangle(height, width) {
this.height = height;
this.width = width;
this.calcArea = function() {
return this.height * this.width;
};
// put our perimeter function here!
this.calcParimeter = function() {
return 2 * this.height + 2 * this.width
};
}

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();

Hi guys whenever I type this in I get a response saying "When the computer tried to call calcPerimeter of a Rectangle object, the following error was thrown: TypeError: rec_test.calcPerimeter is not a function

so what am I doing wrong?


#2

@potato1001,

Have close look at

calcParimeter


#3

Hint, hint -- look at how you spell perimeter


#4

I didn't see that! I have been stuck for WEEKS just because of that same problem!!!


#5

whene you create the second method you type:

this.P**a**rimeter = function(){}....

at the very end you try to call a methdo with the name rex.calcPerimeter(); which obviously doesnt exists!
So you either change this.Parimeter or rex.Perimeter()!! your choice!