Tell us what’s happening:
Describe your issue in detail here.
Your code so far
function checkCashRegister(price, cash, cid) {
let change = cash - price;
let totalCid = 0;
for (let i = 0; i < cid.length; i++) {
totalCid += cid[i][1];
}
totalCid = totalCid.toFixed(2);
if (totalCid < change) {
return { status: "INSUFFICIENT_FUNDS", change: [] };
} else if (totalCid == change) {
return { status: "CLOSED", change: cid };
} else {
let changeArr = [];
const currencyUnit = [
["ONE HUNDRED", 100],
["TWENTY", 20],
["TEN", 10],
["FIVE", 5],
["ONE", 1],
["QUARTER", 0.25],
["DIME", 0.1],
["NICKEL", 0.05],
["PENNY", 0.01]
];
for (let i = 0; i < currencyUnit.length; i++) {
let currencyValue = 0;
while (cid[i][1] > 0 && change >= currencyUnit[i][1]) {
change -= currencyUnit[i][1];
cid[i][1] -= currencyUnit[i][1];
currencyValue += currencyUnit[i][1];
change = change.toFixed(2);
}
if (currencyValue > 0) {
changeArr.push([currencyUnit[i][0], currencyValue]);
}
}
if (change > 0) {
return { status: "INSUFFICIENT_FUNDS", change: [] };
} else {
return { status: "OPEN", change: changeArr };
}
}
}
console.log(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]
]));
//This return tonnes of error that I can not even debug. I understand that it is a test best kindly seek for help from those that have passed this stage or anyone that can. Thanks @all
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Challenge Information:
JavaScript Algorithms and Data Structures Projects - Cash Register