-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangle.js
56 lines (40 loc) · 1.45 KB
/
triangle.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function getSideA() {
const sideA = document.getElementById("input-triangle-a").value;
return sideA;
}
function getSideB() {
const sideB = document.getElementById("input-triangle-b").value;
return sideB;
}
function getSideC() {
const sideC = document.getElementById("input-triangle-c").value;
return sideC;
}
function calculatePerimeter() {
const sideA = parseFloat(getSideA());
const sideB = parseFloat(getSideB());
const sideC = parseFloat(getSideC());
const perimeterTriangle = (sideA + sideB + sideC);
const resultPerimeter = document.getElementById("result-triangle");
resultPerimeter.innerHTML = ` Perimeter = ${perimeterTriangle} cm`;
return resultPerimeter;
}
function getSemiPerimeter(sideA, sideB, sideC) {
const sp = parseFloat((sideA + sideB + sideC)/2);
return sp;
}
function getAreaTriangle(a, b, c, sP) {
const radicando = parseFloat((sP * (sP - a) * (sP - b) * (sP - c)));
const areaTri = Math.sqrt(radicando);
return areaTri;
}
function calculateArea() {
const sideA = parseFloat(getSideA());
const sideB = parseFloat(getSideB());
const sideC = parseFloat(getSideC());
const semiPerimeter = getSemiPerimeter(sideA, sideB, sideC);
const areaTriangle = getAreaTriangle(sideA, sideB, sideC, semiPerimeter);
resultArea = document.getElementById("result-triangle");
resultArea.innerHTML = `Area triangle = ${areaTriangle} cm^2`;
return resultArea;
}