# Cash Register challenge needs explanation

hello , i am trying to solve challenge " Cash Register", and i solved some of its scenarios but i am stuck in these two scenarions i can’t understand this one, can any one explain this case for me please ?

`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]])` should return `{status: "OPEN", change: [["QUARTER", 0.5]]}` .

This says that you should get 50cents change when you pay with \$20 and only \$19.50 is due.

hi Jermey,

this is my code, but i still thinking about logic for case i posted

``````function checkCashRegister(price, cash, cid) {

var change= cash - price;
var totalCID=0;
var obj;

///calculating total in drawer
for (var i=0;i<cid.length;i++)
{

totalCID += cid[i][1];
}

if (totalCID < change || totalCID>=1)
{
obj= {status: "INSUFFICIENT_FUNDS", change: []};
}

else if (totalCID === change)
{
obj= {status: "CLOSED", change: cid };
}

else
object = {status: "OPEN", change:cid};
}

return obj;

} `````````

I mean why it returned value of “QUARTER” only not another value , although the requirement was to return `{status: "OPEN", change: [...]}` , with the change due in coins and bills, sorted in highest to lowest order.

same for this scenario

`checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])` should return `{status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}` .

why it didn’t return [“ONE HUNDRED”, 100]] in the returned sorted array??

Only 50 cents in quarters is the expected change.

In the second case you mention, a 100 dollar bill is not part of the change being given back.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.