-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (23 loc) · 833 Bytes
/
script.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
//Element can be toggled on and off when checkbox is checked
const checkBox = document.getElementById("split_btn");
const people = document.getElementById("people");
const bill = document.getElementById("bill");
const tip = document.getElementById("tip");
const calculate = document.getElementById("calculate");
const results = document.getElementById("results");
//Element is displayed when checkbox is checked by passing var through an event
checkBox.addEventListener("click", (e)=>{
if (checkBox.checked) {
people.style.display = "block";
} else {
people.style.display = "none";
}
});
calculate.addEventListener("click", (e)=>{
if ((bill.value == "") || (people.value == "" )) {
alert("Enter Value");
return
}
let sum = (bill.value * (tip.value/100)/people.value)
results.innerHTML = sum
})