24/33


#1

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

Oops, try again. It looks like you have an error in your code. Here's the message: TypeError: rex.calcArea is not a function


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

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


#2

You're setting two Rectangle constructors but you only need 1 with your 2 methods in it. That's the cool thing about objects. You can set any method related to it in just one constructor instead of multiple!

Just add your this.calcPerimeter method into your first Rectangle constructor (after this.calcArea method) and remove everything else in your second constructor.


#3

thx ive been looking at tht forever


#4

No Problem! Have fun coding :slight_smile:


#5

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