Tell us what’s happening:
Sombody who can support me
Your code so far
function checkCashRegister(price, cash, cid) {
let change = cash - price;
let cashIn = cid.reduce((acc, curr) => acc + curr[1],0).toFixed(2);
let currAmt = [["PENNY", .01], ["NICKEL", .05], ["DIME", .1], ["QUARTER", .25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
currAmt.reverse();
cid.reverse();
for(let i = 0;i < currAmt.length;i++){
if(cashIn < change || change / currAmt < 1){
console.log ({status: "INSUFFICIENT_FUNDS", change: []});
}
if(cashIn == change){
console.log({status: "CLOSED", change: cid.reverse()});
}
if(change / currAmt[i][1] < 1){
let chtG = cashIn -cid[i][1];
if (change > chtG){
console.log({status: "ISUFFICIENT_FUNDS", change: []});
}
let arrN = '';
let arrW = '';
let arrZ = '';
if (change < chtG){
for(let j in currAmt){
if(change / currAmt[j][1] >= 1){
arrN += currAmt[j]
let chMon = Math.floor(change / currAmt[j][1]) * currAmt[j][1];
if (chMon > cid[j][1]){
change -= cid[j][1];
change = change.toFixed(2);
}
if (chMon < cid[j][1]){
change -= chMon;
change = change.toFixed(2);
cid[j][1] -= (cid[j][1] - chMon);}
if (cid[j][1] < .5)
cid[j][1] = cid[j][1].toFixed(2)
arrZ += '[' + cid[j] +']' + ',' ;
}
}
console.log(arrZ);
}
}
}
}
checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NrICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
Your browser information:
El agente de usuario es: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Algoritmos de JavaScript y proyectos de estructuras de datos - Caja registradora