-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
45 lines (32 loc) · 994 Bytes
/
helpers.js
File metadata and controls
45 lines (32 loc) · 994 Bytes
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
// accepts 'tipAmt', 'billAmt', 'tipPercent' and sums total from allPayments objects
function sumPaymentTotal(type) {
let total = 0;
for (let key in allPayments) {
let payment = allPayments[key];
total += Number(payment[type]);
}
return total;
}
// converts the bill and tip amount into a tip percent
function calculateTipPercent(billAmt, tipAmt) {
return Math.round(100 / (billAmt / tipAmt));
}
// expects a table row element, appends a newly created td element from the value
function appendTd(tr, value) {
let newTd = document.createElement('td');
newTd.innerText = value;
tr.append(newTd);
}
function appendDeleteBtn(tr, type) {
let new Td = document.createElement('td');
newTd.className = 'deleteBtn';
newTd.innerText = 'X';
newTd.addEventListener('click', removeEle);
tr.append(newTd);
}
function removeEle(evt) {
let ele = evt.target.closest('tr');
delete allServers[ele.id];
ele.parentNode.removeChild(ele);
updateServerTable();
}