# Not passing one test Case, can anybody help?

Tell us what’s happening:
Describe your issue in detail here.

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

let arr=[];
let cd = JSON.parse(JSON.stringify(cid));
console.log(cd)
let cidTotal=cid.reduce((total,elem)=> total+elem[1],0).toFixed(2)
console.log("total : "+cidTotal)

function chan(amount)
{
amount=parseFloat(amount).toFixed(2)
if(cd[8][1]>=100 && amount>=100)
{
amount-=100;
cd[8][1]-=100
chan(parseFloat(amount).toFixed(2))
}
else if(cd[7][1]>=20 && amount>=20)
{
amount-=20
cd[7][1]-=20
console.log(parseFloat(amount).toFixed(2))
arr[7]
chan(parseFloat(amount).toFixed(2))
}
else if(cd[6][1]>=10 && amount>=10)
{
amount-=10
cd[6][1]-=10
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}
else if(cd[5][1]>=5 && amount>=5)
{
amount-=5
cd[5][1]-=5
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}
else if(cd[4][1]>=1 && amount>=1)
{
amount-=1..toFixed(2)
cd[4][1]-=1
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}
else if(cd[3][1]>=0.5 && amount>=0.5)
{
amount-=0.5
cd[3][1]-=0.5
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}
else if(cd[2][1]>=0.1 && amount>=0.1)
{
amount-=0.1
cd[2][1]-=0.1
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}
else if(cd[1][1]>=0.05 && amount>=0.05)
{
amount-=0.05
cd[1][1]-=0.05
console.log(amount)
chan(parseFloat(amount).toFixed(2))
}
else if(cd[0][1]>=0.01 && amount>=0.01)
{
amount-=0.01
cd[0][1]-=0.01
console.log(parseFloat(amount).toFixed(2))
chan(parseFloat(amount).toFixed(2))
}

}

let result={status:'',change:[]}
let change=cash-price
console.log("return :   "+parseFloat(change))

if(cidTotal==change)
{
result.status="CLOSED"
console.log("CLOSED")
chan(change)

result.change=[["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]
console.log(result)
return result

}
else if(cidTotal>change)
{
console.log("OPEN")
result.status="OPEN"
chan(change)

for(let i=0;i<8;i++)
{
if(cd[i][1]!==cid[i][1])
{
let num=cid[i][1]-cd[i][1]
//console.log(Number.isInteger(num))
if(!Number.isInteger(num))
{
num=parseFloat(num.toFixed(2))
}

arr.unshift([cid[i][0],num])
}
}
//console.log(arr)
result.change=arr
let arrTotal=arr.reduce((tot,curr)=>tot+curr)
if(arrTotal<cidTotal)
{
result.change=[]
}
console.log(result)
return result
}

return true;
}

checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])
``````
``````   **Your browser information:**
``````

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

Challenge: Cash Register

You need a condition to check if the money left in the register can make the change.

For instance if a guy comes to you with \$19.5 worth of stuff and a \$20 dollar bill, you need to have whatever number of coins to make the change total equal to \$0.5.

If your register has only a penny and a dollar coin, then even though mathematically you have enough money to make the \$0.5 change, realistically you cannot give exact change.

You either give only the penny, giving the customer \$0.49 less than you should, or give the dollar, giving the customer \$0.5 more than you should. In this case, it should return insufficient funds.

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