-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
21 lines (17 loc) · 986 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function calculateTip() {
const amountBillElement = document.getElementById('amountBill');
const percentageTipElement = document.getElementById('percentageTip');
const peopleNumberElement = document.getElementById('peopleNumber');
const billAmount = Math.abs(parseInt(amountBillElement.value));
const tipPercentage = Math.abs(parseInt(percentageTipElement.value));
const peolpeNumber = Math.abs(parseInt(peopleNumberElement.value));
amountBillElement.value = billAmount;
percentageTipElement.value = tipPercentage;
peopleNumberElement.value = peolpeNumber;
const totalTip = Math.floor((billAmount * tipPercentage)) / 100;
const totalToPay = billAmount + totalTip;
const tipPerPerson = Math.floor(totalTip * 100 / peolpeNumber) / 100;
document.getElementById('tipAmount').innerText = totalTip;
document.getElementById('totalPay').innerText = totalToPay;
document.getElementById('perPerson').innerText = tipPerPerson;
}