-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypotenuse.js
24 lines (20 loc) · 907 Bytes
/
hypotenuse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const perpendicular = document.querySelector("#perpendicular");
const base = document.querySelector("#base");
const calHypotenuse = document.querySelector("#btn-hypotenuse");
const hypotenuseOutput = document.querySelector("#hypotenuse-output");
function calculateSumOfSquares(perpendicular,base){
const sumOfSquares = perpendicular*perpendicular + base*base;
return sumOfSquares;
}
function calculateHypotenuse(){
if(Number(perpendicular.value) > 0 && Number(base.value) > 0)
{
const sumOfSquares = calculateSumOfSquares(Number(perpendicular.value), Number(base.value));
const result = Math.sqrt(sumOfSquares);
hypotenuseOutput.innerText = "The Length of Hypotenuse is " + result + " unit";
}
else{
hypotenuseOutput.innerText = "Please Enter both the fields🤦♂️";
}
}
calHypotenuse.addEventListener("click", calculateHypotenuse);