24. Constructors With Methods


#1



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


I need a working code to compare.


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

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


#2

@nsanjay,
Try it by changing your

into

this.calcPerimeter = function (height, width) {
        return 2 * this.height + 2 * this.width;
    }

#3

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 * 2) + (this.width * 2);
}};

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