# Problem with Cash register Problem

Tell us what’s happening:
The way this problem is designed, I guess there’s some problem with the 5th test. can anyone help me with what I should do to return all the denominations
only when the status is closed.

``````
function checkCashRegister(price, cash, cid) {
let denom = [
{ name: "ONE HUNDRED", val: 100.0 },
{ name: "TWENTY", val: 20.0 },
{ name: "TEN", val: 10.0 },
{ name: "FIVE", val: 5.0 },
{ name: "ONE", val: 1.0 },
{ name: "QUARTER", val: 0.25 },
{ name: "DIME", val: 0.1 },
{ name: "NICKEL", val: 0.05 },
{ name: "PENNY", val: 0.01 }
];
let change = cash-price;
let changeArr=[],f=0,ctr=0;
let totalCash =0;
cid.map(item=>{
totalCash+=item[1];
denom.map(den=>{
if(den.name===item[0]){
den.fund = item[1]
}
})
});
if(totalCash<change)
return {status: "INSUFFICIENT_FUNDS", change: []};
denom = denom.map((den)=>{
ctr=0;  f=0;
while(change>=den.val && den.fund>=den.val){
change-=den.val;
den.fund-=den.val;
change = Math.round(change*100)/100;
den.fund = Math.round(den.fund*100)/100;
ctr++
f=1;
}

if(f===1){
changeArr.push([den.name, ctr*den.val])

}

return den;

})
totalCash=0;
denom.map(den=>{
totalCash+=den.fund;
})
if(change!==0){
return {status: "INSUFFICIENT_FUNDS", change: []};
}
console.log(totalCash, changeArr)
if(totalCash==0)
return {status:'CLOSED', change:changeArr};

return {status:'OPEN', change:changeArr};
}

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

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0`.

Challenge: Cash Register

i dont think this part looks good, for calculating the total cash, use

``````var totalCash = cid.reduce(accumulator, elem)=>accumulator+elem[1])
``````

also, for the `change` variable use `var` keword, for variables that you’d need to access within the whole function (in multiple loops and if statements) it’s better to use `var` keyword

where are the curly braces for the if?
if you want to write it without them don’t have a new line

also, when you’re using `map` remember that it returns a new array, it doesnt change the array it acts on, when you want to change an array with `map` use

``````array_name = array_name.map(actions)
``````