24. Constructor with Methods



"TypeError: rex.calcArea is not a function"

Replace this line with your code. 
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 this.height + this.width;

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


function Rectangle(height, width) {  did you close this function?


If I close it, I get this messege...TypeError: rex.calcArea is not a function


it should be.because rex.calcArea should be inside of Rectangle function.


Check your curly brackets. You are creating the Rectangle object and its methods so you don't need the curly bracket after the this.width = width; line - it needs to close out the whole thing at the very end but prior to the declaration of the last three variables.

tl;dr - You need to close out the this.calcPerimeter method (add one more closing bracket). That should work (though your equation to solve for the perimeter is incorrect).

I hope this helps!


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