I can’t figure out how to get the perimeter of a triangle. I’ve tried
let triangle = new Shape('triangle', 3, 10);
I can’t figure out how to get the perimeter of a triangle. I’ve tried
let triangle = new Shape('triangle', 3, 10);
Hi there @Green_Marble, and welcome to the community. Thanks for sending in your code!
So the formula you have for the calcArea()
is actually correct for calcPerimeter()
— the length of each side multiplied by the number of sides.
So if you change the calcPerimeter()
definition to
calcPerimeter() {
console.log(`${this.sides * this.sideLength}`);
}
You can then call the method using this:
let triangle = new Shape('triangle', 3, 10);
triangle.calcPerimeter();
As for the triangle’s calcArea()
method, I didn’t include this in any of the questions. If we assume the triangle is an equalateral triangle (because the sides are all the same length), we can then search for the formula:
Area = (a2√3)/4
Where a is the sideLength.
Try implementing this in your JS, and see where you get.