How to Find the Height of an Isosceles Triangle in JavaScript

08/01/2021

Contents

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

Finding the height of an isosceles triangle in JavaScript

An isosceles triangle is a triangle in which two sides are equal in length. To find the height of an isosceles triangle in JavaScript, we can use the Pythagorean theorem, which states that in a right triangle, the sum of the squares of the two legs (the sides that form the right angle) is equal to the square of the hypotenuse (the side opposite the right angle). If we know the length of the two equal sides of an isosceles triangle and the length of the base (the third side), we can use the Pythagorean theorem to find the height of the triangle.

The formula to find the height of an isosceles triangle is:

Height = sqrt(Side^2 - (Base/2)^2)

where Side is the length of either of the two equal sides, Base is the length of the base, and sqrt() is the square root function.

Examples

Finding the height 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);
console.log(height); // 4.0

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 height of the isosceles triangle, which is 4.0 units.

Finding the height 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);
console.log(height); // 9.202374707734802

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 height of the isosceles triangle, which is approximately 9.20 units.

Finding the height 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);
console.log(height); // 2.23606797749979

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 height of the isosceles triangle, which is approximately 2.24 units.