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:, part OOJS1
I have tried below:

function Shape(name, sides, sideLength) { = 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);


const triangle= new Shape(‘triangle’,3,3);
I’m thinking to add a method into the object Shape as above, but I was told Shape.calcPerimeter is not a function.

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: