24. Constructor with Methods


#1


https://www.codecademy.com/en/courses/spencer-sandbox/3/5?curriculum_id=506324b3a7dffd00020bf661

"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();


#2

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

#3

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


#4

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


#5

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!


#6

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