24 constructor with methods


#1

Hi all,

My code seems to throw the following message and I'm not sure why. I get his message TypeError: rex.calcPerimeter is not a function

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

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


#2

You have to remove one of the curly brackets before your perimeter function and put it after the perimeter function because your perimeter function should be inside the Rectangle function and not out.


#3

Your Code

// put our perimeter function here!
this.calcPerimeter = function(){
return 2*(this.height + this.width); Here you need to take away the () in "this height & this width" and also get rid of_ this_ in "this height and this width
};


#4

Thanks for the tips.


#5

I can see where i made the mistakes