Pls help with new object definition in OOJS1, link inside

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

Hello @Mia_Woody

you doing great just change to that
Shape.prototype.calcPerimeter=function ()

you missed the prototype and have a nice day :slight_smile:

1 Like

Brilliant. Thanks very much. Yes, it’s working now

Have a good day.

you very welcome and thanks a lot you too :slight_smile: