# Cash register wont register

Tell us what’s happening:

ive realized that I don’t really know how to use this forum. Everything I do turns out to be wrong and I hope this isn’t either. I have tried to wrap my head around the solution of this problem forever and I’ve tried countless methods. My own and others but I always come short. I hope someone can tell me whats wrong with this code so that maybe i can understand all my short comings. I’ve learned that coding is hard and it can lead you to a slight depression. Someone plz tell me what to change so that it passes the test.

function checkCashRegister(price, cash, cid) {
let stat = {status: “OPEN”, change: };
let tot = 0;
for (let coin of cid) {
tot += coin[1];
}
let total = tot.toFixed(2);
let newarr = ;
let cd = JSON.parse(JSON.stringify(cid));

function changer(chan) {
chan = Number(chan.toFixed(2));

if (chan >= 100 && cd[8][1] >= 100) {
cd[8][1] -= 100;
changer(chan - 100);
} else if (chan >= 20 && cd[7][1] >= 20) {
cd[7][1] -= 20;
changer(chan - 20);
} else if (chan >= 10 && cd[6][1] >= 10) {
cd[6][1] -= 10;
changer(chan - 10);
} else if (chan >= 5 && cd[5][1] >= 5) {
cd[5][1] -= 5;
changer(chan - 5);
} else if (chan >= 1 && cd[4][1] >= 1) {
cd[4][1] -= 1;
changer(chan - 1);
} else if (chan >= 0.25 && cd[3][1] >= 0.25) {
cd[3][1] -= 0.25;
changer(chan - 0.25);
} else if (chan >= 0.1 && cd[2][1] >= 0.1) {
cd[2][1] -= 0.1;
changer(chan - 0.1);
} else if (chan >= 0.05 && cd[1][1] >= 0.05) {
cd[1][1] -= 0.05;
changer(chan - 0.05);
} else if (chan >= 0.01 && cd[0][1] >= 0.01) {
cd[0][1] -= 0.01;
changer(chan - 0.01);
}

newarr.push([cd[8][0],cid[8][1]-cd[8][1]],[cd[7][0],cid[7][1]-cd[7][1]],[cd[6][0],cid[6][1]-cd[6][1]],[cd[5][0],cid[5][1]-cd[5][1]],[cd[4][0],cid[4][1]-cd[4][1]],[cd[3][0],cid[3][1]-cd[3][1]],[cd[2][0],Number((cid[2][1]-cd[2][1]).toFixed(2))],[cd[1][0],cid[1][1]-cd[1][1]],[cd[0][0],Number((cid[0][1]-cd[0][1]).toFixed(2))]);
return newarr;
}

let obj;
if (total < cash-price) {
stat.status = “INSUFFICIENT_FUNDS”;
stat.change = ;
} else if (total == cash-price) {
stat.status = “CLOSED”;
stat.change = cid;
} else {
stat.status = “OPEN”;
obj = changer(cash-price);
for (let i = 0; i<9;i++) {
if (obj[i][1] != 0) {
stat.change.push(obj[i]);
}
}
}
console.log(stat)
return stat;
}

checkCashRegister(19.5, 20, [[“PENNY”, 0.01], [“NICKEL”, 0], [“DIME”, 0], [“QUARTER”, 0], [“ONE”, 1], [“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],

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