# Cash register, case 6, status "CLOSED"

Tell us what’s happening:
Cash register passes all tests except case 6. Output is equivalent, but still fails. Please help as I can’t figure out why this one is still failing.

``````  **Your code so far**
``````
``````function checkCashRegister(price, cash, cid) {

let totalCash = Math.round(cid.reduce((sum, item) => sum + item[1],0)*100)/100;
console.log(price + ", " + cash + ", " + cid);
//console.log("CID:     \$" + totalCash);
let totalChange = cash - price;
let remainder = totalChange;
console.log("change 1: " + totalChange);
let giveBack = [...cid];
let takeOut = [];
let totalGiveBack = 0;
let denomTypes = cid.length;
// console.log(cid);
//get return denomination value
function getDenomValue(denom){
switch (denom){
case "ONE HUNDRED":
return 100;   break;
case "TWENTY":
return 20;    break;
case "TEN":
return 10;    break;
case "FIVE":
return 5;     break;
case "ONE":
return 1;     break;
case "QUARTER":
return 0.25;  break;
case "DIME":
return 0.1;   break;
case "NICKEL":
return 0.05;  break;
case "PENNY":
return 0.01;  break;
} }
//check sufficient change

if (totalChange>totalCash){
return {status: "INSUFFICIENT_FUNDS", change: []}
}
//if sufficient change then get change
for(let i=cid.length-1; remainder>=0&&i>=0; i--){
//console.log("change 2: " +remainder)
let denomValue = getDenomValue(giveBack[i][0]);
//console.log("denomVal: " + denomValue);
if (denomValue<remainder){
if (Math.floor(remainder/denomValue)<=Math.floor(cid[i][1]/denomValue)){
giveBack[i][1]=Math.floor(remainder/denomValue)*denomValue;
} else {}
//console.log("allocated: " + giveBack[i][1])
remainder = Math.round((remainder - giveBack[i][1])*100)/100;
//console.log("remainder: " + remainder);
if(giveBack[i][1]>0){takeOut.push(giveBack[i]);
//console.log(takeOut);
}
} else {giveBack.splice(i,1);}
}

totalGiveBack = Math.round(giveBack.reduce((sum, item) => sum + item[1],0)*100)/100;
//console.log("remaining change = \$" + remainder);
//console.log(giveBack);
if (remainder>0){
} else if (remainder===0&&totalGiveBack===totalCash){
} else if (remainder===0&&totalGiveBack<=totalCash){
} else {console.log("unknown")};
}

checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//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/102.0.5005.124 Safari/537.36 Edg/102.0.1245.41`

Challenge: Cash Register

your `answer` obj should contain `cid` for `change` property which has `CLOSED` status