-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (27 loc) · 1.06 KB
/
script.js
File metadata and controls
32 lines (27 loc) · 1.06 KB
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
function calculateTip(event) {
event.preventDefault();
let bill = document.getElementById('bill').value;
let serviceQuality = document.getElementById('serviceQuality').value;
let numOfPeople = document.getElementById('people').value;
if(bill < 0) {
alert('O valor não pode ser negativo.');
return;
}
if(numOfPeople < 1) {
alert('Número de pessoas não pode ser negativo.');
return;
}
if(numOfPeople == "") {
numOfPeople = 1;
document.getElementById('each').style.display = "none";
}
else {
document.getElementById('each').style.display = "block";
}
let total = (bill * serviceQuality) / 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);