In this

**HackerRank Day 4: Classes 10 days of javascript problem solution**Create a Polygon class that has the following properties:- A constructor that takes an array of integer values describing the lengths of the polygon's sides.
- A perimeter() method that returns the polygon's perimeter.
- Locked code in the editor tests the Polygon constructor and the perimeter method.

## Problem solution in JavaScript programming.

/* * Implement a Polygon class with the following properties: * 1. A constructor that takes an array of integer side lengths. * 2. A 'perimeter' method that returns the sum of the Polygon's side lengths. */ class Polygon { constructor(lengths) { this.lengths = lengths; } perimeter() { let perimeter = 0; for (let i = 0; i < this.lengths.length; i++) { perimeter += this.lengths[i]; } return perimeter; } }

## 0 Comments