Tell us what’s happening:
Please, can someone help me with this problem?
Your code so far
function checkCashRegister(price, cash, cid) {
const DRAWER = {
PENNY: 0.01,
NICKEL: 0.05,
DIME: 0.1,
QUARTER: 0.25,
ONE: 1,
FIVE: 5,
TEN: 10,
TWENTY: 20,
"ONE HUNDRED": 100
};
let change = cash - price;
let drawer = cid.reduce((sum, [denomination, amount]) => {
sum[denomination] = {
denomination: denomination,
amount: amount
};
return sum;
}, {});
for (let denomination in DRAWER) {
while (change >= DRAWER[denomination] && drawer[denomination].amount > 0) {
change -= DRAWER[denomination];
drawer[denomination].amount--;
change = Math.round(change * 100) / 100;
}
}
if (change > 0) {
return { status: "INSUFFICIENT_FUNDS", change: [] };
}
let drawerChange = [];
for (let denomination in drawer) {
if (drawer[denomination].amount > 0) {
drawerChange.push([denomination, drawer[denomination].amount * DRAWER[denomination]]);
}
}
if (drawerChange.reduce((sum, [denomination, amount]) => sum + amount, 0) === cid.reduce((sum, [denomination, amount]) => sum + amount, 0)) {
return { status: "CLOSED", change: cid };
}
return { status: "OPEN", change: drawerChange };
}
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
JavaScript Algorithms and Data Structures Projects - Cash Register