-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower.js
103 lines (92 loc) · 3.16 KB
/
power.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var totalp = document.querySelector("#tprice");
var paidp = document.querySelector("#paid");
var sub = document.querySelector("#mutton");
var noteBlocks = document.querySelector(".noteBlock");
var eror = document.querySelector(".error");
var leftamount = document.querySelector(".leftamt");
var money = [2000, 500, 200, 100, 20, 10, 5, 1];
var a = 0;
function clearous(){
noteBlocks.innerText = "";
leftamount.innerText = "";
noteBlocks.style.margin = "0rem 0rem 0rem 0rem";
// noteBlocks.style.border = "0rem";
}
function errors(total,paid){
clearous();
eror.innerHTML = "";
if(paid == "" || total == ""){
eror.innerHTML = "Input can't be empty";
console.log("1");
}
else if(total < 0 || paid < 0){
eror.innerHTML = "Input can't be negative"
console.log("2");
}
// if(paid == "" || total == "" || paid < 0 || total < 0){
// try {
// if(total == "" || paid == "") throw "can't be empty";
// if(total < 0 || paid < 0) throw "can't be negative";
// }
// catch(err) {
// eror.innerHTML = "Input " + err;
// }
// }
else if(Number(paid) < Number(total)){
eror.innerHTML = "Sorry Paid amount is less then Total amount";
console.log("3");
}
else if(Number(paid) == Number(total)){
eror.innerHTML = "No Amount left";
console.log("4");
}
else{
process(total,paid);
console.log( total + paid);
}
}
function process(total, paid){
clearous();
var nbcsmall = window.matchMedia("(max-width: 376px)");
var nbc = window.matchMedia("(max-width: 416px)");
if(nbc.matches){
noteBlocks.style.margin = "2rem 0rem 0rem 0rem";
}
else if(nbcsmall){
noteBlocks.style.margin = "1.3rem"
}
else{
noteBlocks.style.margin = "0rem 0rem 5rem 18rem";
}
var leftAmt = paid - total;
leftamount.innerText = "Left Amount → " + "₹ " +leftAmt;
var head = document.createElement('div');
noteBlocks.appendChild(head);
head.innerText = " Notes to Return!"
head.style.margin = "1rem 0rem 0.8rem 0rem";
head.style.animation = "lists 1s ease";
head.style.textAlign = "center";
for(var i = 0; i < 8; i++){
if(parseInt(leftAmt) >= money[i]){
console.log(leftAmt)
var quo = parseInt(leftAmt / money[i]);
console.log(money[i]);
var rem = parseInt(leftAmt) - (parseInt(quo) * money[i]);
var res = parseInt(quo);
// var image = document.createElement('img');
// image.src = 'iconmonstr-currency-25.svg';
var list = document.createElement('div');
list.classList.add("liststyle");
list.style.animationDelay = "2s";
list.style.animation = "lists 1s ease";
list.innerHTML = "<img src = \"iconmonstr-currency-25.svg\">";
list.innerText = "₹ " + money[i] + " → " + res;
noteBlocks.appendChild(list);
console.log(quo.toFixed(0) * money[i] + " " + rem);
leftAmt = rem;
if(rem == 0){
break;
}
}
}
}