Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 11, 2023 08:20
Show Gist options
  • Select an option

  • Save codeperfectplus/61de017bb25273a7084b0fe8b4e42507 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/61de017bb25273a7084b0fe8b4e42507 to your computer and use it in GitHub Desktop.
'use strict'
class Polygon{
constructor(sides){
this.sides = sides;
this.perimeter = this.perimeter;
}
perimeter() {
let sum = 0;
for(let i =0;i<this.sides.length;i++) {
sum = sum + this.sides[i];
}
return sum;
}
}
const triangle = new Polygon([3,4,5]);
console.log(triangle.perimeter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment