OOJS 1 solution1:
function Shape(name, sides, sideLength) {
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
this.calcPerimeter = function() {
return (Result of ${this.name} is : ${this.sides*this.sideLength}
);
};
}
// create object
let square = new Shape(“square”, 4, 5);
console.log(square.calcPerimeter());
let triangle = new Shape(“triangle”, 3, 3);
console.log(triangle.calcPerimeter());
OOJS 1 solution2:
function Shape(name, sides, sideLength) {
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
this.calcPerimeter = function() {
if (this.name === "square") {
console.log(sideLength * sides);
} else if (this.name === "triangle") {
console.log(sideLength * sides);
}
};
}
// create object
let square = new Shape(“square”, 4, 5);
console.log(square.calcPerimeter());
let triangle = new Shape(“triangle”, 3, 3);
console.log(triangle.calcPerimeter());