-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (42 loc) · 1.45 KB
/
app.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
const billInput = document.getElementById("bill");
const tipAmount = document.querySelector(".tip-amount");
const billTotal = document.querySelector(".total-amount");
const peopleNumber = document.getElementById("people-number");
const resetBtn = document.querySelector(".reset-btn");
const customTip = document.querySelector(".custom");
const tipSelect = document.querySelectorAll(".percent");
tipSelect.forEach((tip) => {
tip.addEventListener("click", (e) => {
if (e.target.value <= "0.1") {
tipAmount.innerText = "$" + (billInput.value * e.target.value).toFixed(2);
} else {
tipAmount.innerText = "$" + (billInput.value * e.target.value).toFixed(2);
}
});
});
customTip.addEventListener("input", (e) => {
if (customTip.value == "") {
return;
} else {
tipAmount.innerText =
"$" + ((billInput.value * customTip.value) / 100).toFixed(2);
}
});
peopleNumber.addEventListener("input", () => {
if (peopleNumber.value === "") {
billTotal.innerText = "$" + billInput.value;
} else {
billTotal.innerText =
"$" + (billInput.value / peopleNumber.value).toFixed(2);
}
});
// Reset Button
resetBtn.addEventListener("click", () => {
billInput.value = "";
customTip.value = "";
peopleNumber.value = "";
tipAmount.textContent = "$0.00";
billTotal.textContent = "$0.00";
// tipCalc();
});
// (tipAmount.innerText = "$" + (billInput.value * e.target.value) / 10);