-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-area.js
More file actions
28 lines (25 loc) · 965 Bytes
/
Copy pathscript-area.js
File metadata and controls
28 lines (25 loc) · 965 Bytes
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
// get required elements
const inputBase = document.getElementById("base");
const inputHeight = document.getElementById("height");
const btnGetArea = document.getElementById("btn-get-area");
const divOutput = document.getElementById("div-output");
// addEventListener for btn-get-area click
btnGetArea.addEventListener("click", () => {
// get sum of elements
if (inputBase.value !== "" || inputBase.value !== "") {
const area = getArea(inputBase.value, inputHeight.value);
inform(area);
} else inform();
});
// arrow function to calculate area.
const getArea = (base, height) => {
return (base * height) / 2;
};
// arrow function to set the message (result)
const inform = (area = "") => {
let message;
if (area !== "") message = `Area of Triangle = <strong>${area}</strong>`;
else message = "Please enter the values and try again!";
divOutput.innerHTML = message;
divOutput.className = divOutput.className+ " border-norm round-hf";
};