-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (49 loc) · 1.74 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
//disguising html land variables
//input
//cash given shows null --because i forgot hash symbol
var billAmount=document.querySelector("#bill-amount");
var cashGiven=document.querySelector("#cash-given")
var checkButtton=document.querySelector("#check")
var message=document.querySelector("#message")
var noOfNotes=document.querySelectorAll(".no-of-notes")
var nextButton=document.querySelector('#next')
var nextField=document.querySelector('#next-field')
const availableNotes=[2000,500,100,20,10,5,1];
nextField.style.display="none";
nextButton.addEventListener("click",function nextinput(){
if(billAmount.value.length===0){
nextField.style.display="none";
}else{
nextField.style.display="block";
}
})
checkButtton.addEventListener("click",function validateCashAndBill(){
message.style.display="none";
if(billAmount.value>0){
if(cashGiven.value>=billAmount.value){
const amountToBeReturned=cashGiven.value-billAmount.value;
calculateChange(amountToBeReturned)
}
else{
showMessage("Do you want to wash plates?")
}
}
else{
showMessage("Amount should be greater than 0")
}
})
function calculateChange(amountToBeReturned){
for(let i=0;i<availableNotes.length;i++){
const numberOfNotes=Math.trunc(amountToBeReturned/availableNotes[i])//516/500=1
var amountToBeReturned=amountToBeReturned % availableNotes[i];
noOfNotes[i].innerText=numberOfNotes;
}
}
function showMessage(msg) {
message.style.display = "block"
message.innerText = msg;
}
//my errors were
//I did not put noOFNotes and amountToBeReturned in calculateChange inside loop
//did not wire css properly
//no proper table numbers