24.Constructers with methods


#1

I took it step by step why would it even tell me that.

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

There was a problem with you syntax.

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

Hey @devninja93146,

You need to put your perimeter function inside of your Person function and it should return 2 * (this.height + this.width). Fix this and you'll be good to go!


#3

HI you didn't close the Rectangle constructor }


#4

like this ? cause its not working

~~~~
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()};
~~~~


#5

When the computer tried to call calcPerimeter of a Rectangle object, the following error was thrown: TypeError: rec_test.calcPerimeter is not a function


#6

like @bartholomewallen said in the this.calPerimeter you should return

return 2 * (this.height + this.width)

then you should close the function Rectangle

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)
    }
} <.-- #add this one for closing the Rectangle

#7

Solved!
Thanks
~~~~~~
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();
~~~~~~


#8

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