24. Constructors With Methods


#1

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

Why will the code not work. Please help. Thank you.

SyntaxError: Unexpected token ILLEGAL

function Rectangle(height, width) {
  this.height = height;
  this.width = width;
  this.calcArea = function() {
      return this.height * this.width;
  };
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

Hi this part

return 2 * this.Height + 2*this.width

you wrote this.Height intead of this.height with a downcase h


#3

still shows there is a problem with your syntax.


#4

can you post your new code?


#5

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

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

The indentations are done correctly, but they did not copy


#6

HI you code is fine.. if you want to print the results you should use console.log().

Hint

//for the area just put teh name of the variable inside console.log()
console.log(area);


#7

Then why is there a syntax problem


#8

Add a semicolon at the end


#9

HI if your code is like the one you posted before you woudn't have a error


#10

Thanks, i had an unnecessary }.