Constructors With Methods


#1

`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(); `
SyntaxError: Unexpected end of input
@amanuel2 @albionsrefuge @ionatan


#2

you are missing a closing brace for the Rectangle class.

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;
                        };
}//<<== you are missing this

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

Usually when the compiler halts with an error like what you just saw then you should be looking for syntax errors like a missed brace, parenthesis etc


#3

`function Rectangle(height, width) {
this.height = height;
this.width = width;
this.calcArea = function() {
return this.height * this.width;
};
// put our perimeter function here!

}

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


#4

made an edit to the original post


#5

`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(); `
New code and now it says TypeError: rex.calcPerimeter is not a function


#6

take a look at post 2 again. you had the right code you were just missing one curly brace.