How to Find the Area of an Equilateral Triangle in JavaScript

Contents
In this article, you will learn how to find the area of an equilateral triangle in JavaScript.
Finding the area of an equilateral triangle in JavaScript
An equilateral triangle is a triangle in which all three sides are equal in length. To find the area of an equilateral triangle in JavaScript, we can use the following formula:
Area = (Math.sqrt(3) / 4) * Side^2
where Side is the length of any side of the equilateral triangle, and Math.sqrt(3) is the square root of 3, which is approximately equal to 1.73205.
Examples
Finding the area of an equilateral triangle with a side length of 5 units
const side = 5; // in units
const area = (Math.sqrt(3) / 4) * side ** 2;
console.log(area); // 10.825317547305483
In this example, the side length is 5 units, and the output is the area of the equilateral triangle, which is approximately 10.83 square units.
Finding the area of an equilateral triangle with a side length of 10 units
const side = 10; // in units
const area = (Math.sqrt(3) / 4) * side ** 2;
console.log(area); // 43.30127018922193
In this example, the side length is 10 units, and the output is the area of the equilateral triangle, which is approximately 43.30 square units.
Finding the area of an equilateral triangle with a side length of 3.7 units
const side = 3.7; // in units
const area = (Math.sqrt(3) / 4) * side ** 2;
console.log(area); // 6.238492080563358
In this example, the side length is 3.7 units, and the output is the area of the equilateral triangle, which is approximately 6.24 square units.