Constructors with methods


#1

I dont know whats wrong here. Says missing ) after argument list.

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

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();
console.log("rex is a rectangle with"+rex.calcPerimeter() +" as perimeter and " rex.calcArea()+ "as area")


#2

You are missing a + sign in your console.log statement,

console.log("rex is a rectangle with"+rex.calcPerimeter() +" as perimeter and " //here rex.calcArea()+ "as area")

and also you need an extra closing bracket before this one but without a semi colon,

and the closing brackets for your calcArea and calcPerimeter functions do not require semi colons ;


#3

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