Tell us what’s happening:
Describe your issue in detail here.
My code works on VS Code and passes all the tests yet it fails tests two and three when I enter the code on FCC editor.
I have checked the variables for correct spelling and also the status texts.
**Your code so far**
// array of denominations and values
var denoms = [
["ONE HUNDRED", 100.0],
["TWENTY", 20.0],
["TEN", 10.0],
["FIVE", 5.0],
["ONE", 1.0],
["QUARTER", 0.25],
["DIME", 0.1],
["NICKEL", 0.05],
["PENNY", 0.01]
];
function checkCashRegister(price, cash, cid) {
let output = { status: null, change: [] }
let changeArr = [];
let change = cash - price;
// get total amount in cid
let regTotal = cid.reduce((acc, current) => acc + current[1], 0);
// console.log(regTotal);
// when result is exact change
if (regTotal == change) {
output.status = "CLOSED";
output.change = cid;
return output;
}
// when there is insufficient funds
if (regTotal < change) {
output.status = "INSUFFICIENT_FUNDS";
return output;
}
let register = cid.reverse();
let value = null;
for (let i = 0; i < denoms.length; i++) {
value = 0;
if (denoms[i][1] > change) {
// get next lower currency denomination
continue;
} else {
while (register[i][1] > 0 && change >= denoms[i][1]) {
change -= denoms[i][1];
register[i][1] -= denoms[i][1];
value += denoms[i][1];
change = Math.round(change * 100) / 100;
}
}
// if this denom was used then add to changeArr
if (value > 0) {
changeArr.push(denoms[i][0], value);
}
}
// If there are no elements in change_arr or we have leftover
// change, return the string "Insufficient Funds"
if (changeArr.length < 1 || change > 0) {
output.status = "INSUFFICIENT_FUNDS";
return output;
}
// transaction good, change and status returned
output.status = "OPEN";
output.change = changeArr;
return output;
};
**Your browser information:**
Google Chrome : Version 90.0.4430.212 (Official Build) (64-bit)
and VS Code with node.js
Both run my code passing all the tests
Challenge: Cash Register
Link to the challenge: