Can somebody tells me what is wrong?
const DOLLARDICTIONARY = {
'PENNY': 1,
'NICKEL': 5,
'DIME': 10,
'QUARTER': 25,
'ONE': 100,
'FIVE': 500,
'TEN': 1000,
'TWENTY': 2000,
'ONE HUNDRED': 10000
};
function checkCashRegister(price, cash, cid) {
let change= Math.round(cash-price)*100;
let cashBalance={};
let amtToGive={};
cid.forEach(function(denomination){
cashBalance[denomination[0]]=Math.round(denomination[1]*100)
})
let index= DOLLARDICTIONARY.length -1;
while (index>=0 && change>0){
let nameOfMoney =DOLLARDICTIONARY[index][0];
let valueOfMoney= DOLLARDICTIONARY[index][1];
if (change-valueOfMoney >0 && cashBalance[nameOfMoney], amtToGive){
amtToGive[nameOfMoney]=0;
while (cashBalance[nameOfMoney]>0 && change-valueOfMoney>= 0){
cashBalance[nameOfMoney] -= valueOfMoney;
amtToReturn[nameOfMoney] += valueOfMoney;
change-=valueOfMoney;
}
}
index +=1;
}
if (change===0){
let isRegisterEmpty=true;
Object.keys(cashaBlance).forEach(function(moneyType){
if(cashBalance[moneyType]>0){
}
});
if(isRegisterEmpty){
return{
status:"CLOSED", change:cid
}
} else {
let changeArray=[];
Object.keys(amtToReturn).map(function(moneyType){
if (amtToReturn[moneyType]>0){
changeArray.push([moneyType, amtToReturn[moneyType]/100]);
};
});
return {stautus:"OPEN", change: changeArray};
}
}
return {status:"INSUFFICIENT_FUNDS", change:[]};
}
let res = checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])
console.log(res)