# In Cash Register problem ,the 5th test case is wrong?

In Cash Register problem ,the 5th test case is wrong?
0

#1

Tell us what’s happening:

Your code so far

function checkCashRegister(price, cash, cid) {
var change;
change = cash-price;
var len = cid.length,i,count=0,a=0;
for(i=0;i<len;i++){
count = cid[i][1];
if(i==0){count = count*0.01}
else if(i==1){count = count*0.05}
else if(i==2){count = count*0.1}
else if(i==3){count = count*0.25}
else if(i==4){count = count*1}
else if(i==5){count = count*5}
else if(i==6){count = count*10}
else if(i==7){count = count*20}
else {count = count*100}
a = count+a;
}
if((a -change)<0){
return {status:"INSUFFICIENT_FUNDS",change:[]}
}
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

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]]);

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

#2

The reason that test case 5 on the problem is failing is related to this criteria in the problem:

"Return {status: "INSUFFICIENT_FUNDS", change: []} if cash-in-drawer is less than the change due, or if you cannot return the exact change. "

Firstly, it looks like you are multiplying each denomination from cid by its value. If you are trying to get the total money in cash in drawer, you only need to sum the values.

then use the logic

let answer = {status: "", change: []};

if (change > a) {