Get Hypotenuse Using Pythagorean
Supply two sides of a triangle to get the hypotenuse. This simple function uses the Pythagorean Theorem to obtain the hypotenuse.
Javascript:
function pythagorean(x, y) {
return parseInt(Math.sqrt((x * x) + (y * y)), 10);
}
Example:
Given side x = 3, and side y = 4, find the hypotenuse.
x = 3;
y = 4;
console.log(pythagorean(x, y));
The console displays 5.