Constructors with methods


#1

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

SyntaxError: Unexpected end of input.
I don't know what's wrong. Can someone help me?


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


#2

The opening brace on line 1 has no corresponding closing brace (the one on line 10 closes the brace from line 8).


#3

Thank you! That was it!

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) * 2;
};
};
var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();

Now it works!


#4

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