What’s happening:
I can’t understand why I can’t make my code looks similar to the expected output of freeCodeCamp. Its the same on the console but they don’t consider it.
PS: I know that I have to complete the code, but when I change it i cant make it works then I stoped because its so frustrating don’t understand why the input is wrong when all the other stuff sounds ok to me.
That’s my code:
function checkCashRegister(price, cash, cid) {
const monetary = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 0.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]];
const newArr = [];
for (let i = 0; i < monetary.length; i++) {
let monVal = Object.values(monetary[i])
.toString();
let cidVal = Object.values(cid[i])
.toString();
if (monVal != cidVal) {
newArr.push(monVal.split(",").slice(",")[0]);
newArr.push(cidVal.split(",").slice(",")[1] - monVal.split(",").slice(",")[1]);
}
var newObj = {
"status": "OPEN", "change": [newArr]
}
}
if (newArr[1].toString().includes("-") === true) {
var newObj = {
"status": "INSUFFICIENT_FUNDS", "change": []
}
}
return newObj;
}
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]]);
My browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Challenge: Cash Register
Link to the challenge: