Hi, I don’t get how to add a new function/method into an Object constructor. The test is as link below: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_Object-oriented_JavaScript, part OOJS1
I have tried below:
function Shape(name, sides, sideLength) {
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
}
// Write your code below here
Shape.calcPerimeter=function (){
let shapePerimeter=this.sideLength*this.sides;
console.log('The perimeter is '+shapePerimeter);}
var square= new Shape(‘square’,4,5);
square.calcPerimeter();
const triangle= new Shape(‘triangle’,3,3);
square.calcPerimeter();
--------------------------------------
I’m thinking to add a method into the object Shape as above, but I was told Shape.calcPerimeter is not a function.
Thanks