24.constructors with methods


#1


24.constructors with methods


Oops, try again. When the computer tried to call calcPerimeter of a Rectangle object, the following error was thrown: TypeError: rec_test.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

HI you closed the Rectangle object earlier you should close it after the calcPerimeter

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

}<-- #add it here }

#3

thanks but it still doesn't work for me


#4

this line

return 2*this.height+this.width;

put it like that

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

#5

i am still stuck.here is my 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 2*(this.height+this.width);}

var rex = new Rectangle(3,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();
};
here is the error given after the code is run:Oops, try again. Your code caused the following error when the Rectangle constructor was called: RangeError: Maximum call stack size exceeded


#6

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