Cash Register Help, I am stuck :(

Tell us what’s happening:

So far I am able to pass test 1, 4, 5 and 6. I am stuck on tests 2 and 3.

Your code so far


var moneyValue = [{name:'ONE HUNDRED', value:100.00},{name:'TWENTY', value:20.00},{name:'TEN', value:10.00},{name:'FIVE', value:5},{name:'ONE',value: 1.00},{name:'QUARTER', value:0.25},{name:'DIME', value:0.10},{name:'NICKEL', value:0.05},{name:'PENNY', value:0.01}]

function checkCashRegister(price, cash, cid) {
  var change = cash - price;

  var output = {status: null, change: []};

  var cashDrawer = cid.reduce ((accumulator, next)  =>
  accumulator + next[1], 0.0);



  // Handle exact change
  if (cashDrawer === change){
    output.status = 'CLOSED';
    output.change = cid;
    return output;}

  // Handle insufficient funds
  if (cashDrawer < change){
    output.status = 'INSUFFICIENT_FUNDS';
    return output;}

    cid = cid.reverse();

  // Loop through the denomination array
  var cashDue = moneyValue.reduce (function (accumulator, next){
    var currentVal = 0;
     while (cashDrawer[next.name] > 0 && change >= next.value){
       change -= next.value;
       cashDrawer[next.name] -= next.value;
       currentVal += next.value;

      change = Math.round(change * 100) / 100;
    }

    if (currentVal > 0){
      accumulator.push([next.name, currentVal]);
    }
       return accumulator;
 }, []);

 if (cashDue.length  <  1 || change > 0){
   output.status ='INSUFFICIENT_FUNDS';
   return output;
 }

  // Here is your change, ma'am.
    output.status = 'OPEN';
    output.change = cashDue;
    return output;

}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register/