24. Constructors With Methods


#1

Not sure why this code will not run. I keep getting this error: "TypeError: rex.calcPerimeter is not a function
" I don't get whey rex.calcPerimeter is not a function

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
The answer is quite simple: you should place the lines

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

inside the function Rectangle().
Cheerio


#3

Thank you, sir! much appreciated.


#4

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