Hey there campers! I’m stuck…I don’t seem to understand the part where I have to break the change into dollar bills.
I included my code so far below.
I don’t ask about the solution, I want help understanding. Please guide me to the light at the end of this tunnel. I’ve been trying to wrap my brain around it for days.
I gotta say this one is by far the hardest one yet.
Thanks in advance to everyones help.
function checkCashRegister(price, cash, cid) {
function Status(status, change) {
this.status = status;
this.change = change;
}
let moneyUnit = [
["ONE HUNDRED", 10000],
["TWENTY", 2000],
["TEN", 1000],
["FIVE", 500],
["ONE", 100],
["QUARTER", 25],
["DIME", 10],
["NICKEL", 5],
["PENNY", 1]
];
let changeDue = cash*100 - price*100; //change due in pennies
let totalInDrawer = 0;
let changeForCustomer = [];
for (let i = 0; i < cid.length; i++) {
totalInDrawer += cid[i][1]*100; //total in pennies
}
if (totalInDrawer < changeDue) {
let registerStatus = new Status("INSUFFICIENT_FUNDS", []);
} else if (totalInDrawer === changeDue) {
let registerStatus = new Status("CLOSED", cid);
} else {
cid = cid.reverse();
for (let i = 0; i < moneyUnit.length; i++) {
for (let j = 0; j < cid.length; j++) {
while (changeDue >= moneyUnit[i][1] && cid[j] > 0) {
// ????????????? //
// ????????????? //
}
}
}
}
}
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]]);