freeCodeCamp - Cash register

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:

Can you be more specific about the way in which your code is not working? Is it failing a particular test that you think it should pass - if so, what does that failing test say?
I’m a little confused about when you’re converting things to strings. Can you explain that approach?

Hello!

I turned onto a string to use the “include” and the “split”/“slice” to filter the values in the arrays and check if the value was negative. It turned to be a good way to filter the results, but now I noticed that I can made it using only price and cash variables.

My problem is that I don’t know exactly what part I’m having issue all I know is my output, when it returns, isn’t exactly the same from expected ouput and that make it fail but I think that is the same and I don’t know what do.

You’re comparing the values of the cid array with the const monetary
if the values are not equal than push to new array.

You’ll need to calculate the change and use that to check cid in which way you can give the change back to the customer. Keep in mind that the cid argument is the cash you’ll have in the cash register. I would advise to put this line console.log(newObj); above the return newObj; to see what gets returned.