This code is passing the failed test on node but not on FCC can someone tell me what my mistake is?
const currArray = {
'PENNY': 1,
'NICKEL': 5,
'DIME': 10,
'QUARTER': 25,
'DOLLAR': 100,
"FIVE": 500,
"TEN": 1000,
"TWENTY": 2000,
"ONE HUNDRED": 10000,
};
function checkCashRegister(price, cash, cid) {
let changeAmount = cash * 100 - price * 100;
const changeVarUsedLater = changeAmount;
let moneyInDrawer=0;
let message = { status: null, change: [] };
let nonZeroCid = [];
for (let e of cid){
if (e[1]!==0){
nonZeroCid.push(e);
}
}
nonZeroCid.reverse();
// console.log(nonZeroCid);
for (let element of nonZeroCid){
let currency = element[0];
// console.log(currency);
let currencyAvailable = element[1]*100;
moneyInDrawer+=currencyAvailable;
let usedCurrency = 0;
while (changeAmount>=currArray[currency] && currencyAvailable>0){
usedCurrency+=currArray[currency];
changeAmount-=currArray[currency];
currencyAvailable-=currArray[currency];
}
if (usedCurrency !==0){
message.change.push([currency,usedCurrency/100]);
// console.log(message.change);
}
}
if (changeAmount>0){
message.status = 'INSUFFICIENT FUNDS';
message.change=[];
}else if(changeAmount===0 && changeVarUsedLater===moneyInDrawer){
message.status='CLOSED';
message.change=cid; // For some reason FCC wants me to resturn the CID instead of the non null change array
}else{
message.status='OPEN';
}
return message;
}