-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (58 loc) · 1.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let billAmount = 0;
let paidAmount = 0;
const paybackCashAmount = [];
const bill = document.getElementById("bill");
const paid = document.getElementById("paid");
const createTable = (paybackStats) => {
paybackStats.map((cash) => {
let tdElement = document.getElementById(cash.currency);
tdElement.innerHTML = cash.currencyReturn;
if (cash.currencyReturn > 0) {
tdElement.style.color = "#37b24d";
}
});
document.getElementById("show").style.display = "block";
};
const CashReturn = (amountLeft) => {
const cashAvailable = [2000, 500, 100, 20, 10, 5, 1];
let amountToreturn = amountLeft;
let countCash;
cashAvailable.forEach((cashValue) => {
countCash = Math.floor(amountToreturn / cashValue);
amountToreturn = amountToreturn % cashValue;
const returnCash = {
currency: cashValue,
currencyReturn: countCash,
};
paybackCashAmount.push(returnCash);
});
document.getElementById("amount").innerHTML = `Rs ${amountLeft}/-`;
const showAmount = document.getElementById("payback");
showAmount.style.display = "grid";
showAmount.scrollIntoView();
createTable(paybackCashAmount);
};
const CalculateBill = (billA, paidA) => {
customerBill = parseInt(billA);
customerPaid = parseInt(paidA);
if (customerBill > customerPaid) {
return alert("Bill is More Than Paid Amount");
}
ReturnAmount = customerPaid - customerBill;
CashReturn(ReturnAmount);
};
bill.addEventListener("input", (e) => {
const value = e.target.value;
billAmount = value;
});
paid.addEventListener("input", (e) => {
const val = e.target.value;
paidAmount = val;
});
const submit = document.getElementById("btn");
submit.addEventListener("click", () => {
if (billAmount <= 0 || paidAmount <= 0) {
return alert("Enter Valid Amount !!!");
}
CalculateBill(billAmount, paidAmount);
});