Hello !
I’ve got an issue :
I can’t find the solution for the ‘while’ loop…
My reasoning is:
-
Return the CID table, and see if the price difference fits well in the table.
-
For this, I compare from largest to smallest until I can give change…
But I don’t know how to do it at all… and I need help…
**Your code so far**
function checkCashRegister(price, cash, cid) {
let totalAmount = 0;
let diffMoney = cash - price;
cid.forEach(element => {
const [ unit, amount ] = [element[0], element[1]]
totalAmount += amount
})
if(diffMoney > totalAmount ) {
return {status: "INSUFFICIENT_FUNDS", change: []}
} else if (diffMoney === totalAmount) {
return {status: "CLOSED", change: cid}
} else {
cid = cid.reverse()
for( let elem of cid ) {
while()
}
}
}
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]]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Cash Register
Link to the challenge: