How to Find the Area of ​​an Isosceles Triangle in JavaScript

08/01/2021

Contents

In this article, you will learn how to find the area of ​​an isosceles triangle in JavaScript.

Finding the area of an isosceles triangle in JavaScript

An isosceles triangle is a triangle in which two sides are equal in length. To find the area of an isosceles triangle in JavaScript, we can use the formula:

Area = 1/2 * Base * Height

where Base is the length of the base of the triangle, and Height is the height of the triangle, which can be found using the Pythagorean theorem as discussed in the previous answer.

Examples

Finding the area of an isosceles triangle with two sides of length 6 units and a base of length 8 units

const side = 6; // in units
const base = 8; // in units
const height = Math.sqrt(side ** 2 - (base / 2) ** 2);
const area = 0.5 * base * height;
console.log(area); // 12

In this example, the length of the two equal sides is 6 units, the length of the base is 8 units, and the output is the area of the isosceles triangle, which is 12 square units.

Finding the area of an isosceles triangle with two sides of length 10.5 units and a base of length 7 units

const side = 10.5; // in units
const base = 7; // in units
const height = Math.sqrt(side ** 2 - (base / 2) ** 2);
const area = 0.5 * base * height;
console.log(area); // 31.953125

In this example, the length of the two equal sides is 10.5 units, the length of the base is 7 units, and the output is the area of the isosceles triangle, which is approximately 31.95 square units.

Finding the area of an isosceles triangle with two sides of length 3 units and a base of length 5 units

const side = 3; // in units
const base = 5; // in units
const height = Math.sqrt(side ** 2 - (base / 2) ** 2);
const area = 0.5 * base * height;
console.log(area); // 3.5355339059327378

In this example, the length of the two equal sides is 3 units, the length of the base is 5 units, and the output is the area of the isosceles triangle, which is approximately 3.54 square units.