-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
29 lines (23 loc) · 954 Bytes
/
scripts.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
function calculateTip(event) {
event.preventDefault();
let bill = document.getElementById("bill").value;
let qualityService = document.getElementById("qualityService").value;
let numOfPeople = document.getElementById("people").value;
if ((bill == "") | (qualityService == 0)) {
alert("Por favor, preencha os campos!");
return;
}
if ((numOfPeople == "") | (numOfPeople <= 1)) {
numOfPeople = 1;
document.getElementById("each").style.display = "none";
} else {
document.getElementById("each").style.display = "block";
}
let total = (bill * qualityService) / numOfPeople;
total = total.toFixed(2);
document.getElementById("tip").innerHTML = total;
document.getElementById("totalTip").style.display = "block";
}
document.getElementById("totalTip").style.display = "none";
document.getElementById("each").style.display = "none";
document.getElementById("tipsForm").addEventListener("submit", calculateTip);