• + 0 comments

    class Polygon { constructor(sides) { this.sides = sides; } sum = 0; perimeter(){ for(let i = 0; i < this.sides.length; i++) { this.sum = this.sum + this.sides[i]; } return this.sum; } } const poly1 = new Polygon([10, 20, 30]); console.log(poly1.perimeter());

    const poly2 = new Polygon([10, 10, 10, 10]); console.log(poly2.perimeter());

    const poly3 = new Polygon([50, 40, 30, 20, 3]); console.log(poly3.perimeter());

    This code satisfies the condition and produce the expected result in my IDE. However when I try to run the testcases, it prints 2 times. Anybody know why it's happening?