const changeDue = document.getElementById("change-due");
const purchaseBtn = document.getElementById("purchase-btn");
let price = 3.26;
let cid = [
['PENNY', 1.01],
['NICKEL', 2.05],
['DIME', 3.1],
['QUARTER', 4.25],
['ONE', 90],
['FIVE', 55],
['TEN', 20],
['TWENTY', 60],
['ONE HUNDRED', 100]
];
let changeToGive = [
['PENNY', 0],
['NICKEL', 0],
['DIME', 0],
['QUARTER', 0],
['ONE', 0],
['FIVE', 0],
['TEN', 0],
['TWENTY', 0],
['ONE HUNDRED', 0]
];
let poep = [
['PENNY', 0.01],
['NICKEL', 0.05],
['DIME', 0.1],
['QUARTER', 0.25],
['ONE', 1],
['FIVE', 5],
['TEN', 10],
['TWENTY', 20],
['ONE HUNDRED', 100]
];
let sum = 0;
for (let i of cid)
sum += i[1];
function makeTheChange( cash ) {
for (let i = 8; i >= 0; i--) {
while (cash >= poep[i][1] && cid[i][1] > 0) {
cash -= poep[i][1], changeToGive[i][1] += poep[i][1], cid[i][1] -= poep[i][1];
cash = cash.toFixed(2);
}
}
}
purchaseBtn.onclick = function () {
let cash = document.getElementById("cash").value;
console.log( cash );
if (cash < price)
alert("Customer does not have enough money to purchase the item");
else if (cash == price)
changeDue.innerText = "No change due - customer paid with exact cash";
else if (sum < cash - price)
changeDue.innerText = "Status: INSUFFICIENT_FUNDS";
else {
if (sum == cash - price)
changeDue.innerText = "Status: CLOSED";
else
changeDue.innerText = "Status: OPEN";
makeTheChange( cash - price );
for (let i = 8; i >= 0; i -- )
if (changeToGive[i][1] > 0)
changeDue.innerText += `${changeToGive[i][0]}: $${changeToGive[i][1]}`;
}
}
why my code’s outputs are not getting accepted in testcase 12