Cash Register: While loop not exiting when expected

I have been staring at this problem for far too long, and this is where I 'm at: I have the edge cases of there not being enough cash in the drawer at the outset and the case of exact change taken care of. The thing I’m having the most trouble with is the case of returning 'insufficient funds as soon as it’s clear that (while iterating over the drawer) the drawer doesn’t have enough change. I thought the check I put in there would have been enough for that, but it’s not working. Code is:

PS: I realize looking at this that I’m handling the cases of non-exact change completely wrong in this, so no need to mention that :slight_smile:

function checkCashRegister(price, cash, cid) {

  let transaction = {
    status: '',
    change: [
  ["ONE HUNDRED", 0],
  ["TWENTY", 0],
  ["TEN", 0],
  ["FIVE", 0],
  ["ONE", 0],
  ["QUARTER", 0],
  ["DIME", 0],
  ["NICKEL", 0],
  ["PENNY", 0],
]};

  const currencyValue = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01];
  var changeDue = cash - price;
  var cidSubTotal = 0;
  var cidTotal;

  cid.forEach((drawer) => {
    cidSubTotal += (drawer[1] * 100);
  });

  cidTotal = cidSubTotal / 100;

  if (changeDue > cidTotal) {
    transaction.status = "INSUFFICIENT_FUNDS";
    transaction.change = [];
  }

  if (cidTotal === changeDue) {
    transaction.status = "CLOSED";
    transaction.change = cid;
  }

  while (transaction.status == '') {
    let i = 0;
    /* moves the sequence forward if the current denomination is greater than the change due, or if the corresponding denomination doesn't exist in the drawer */
    if (currencyValue[i] > changeDue || (currencyValue[i] < changeDue && comparisonDrawer[i][1] < 0)) {
      i++;
    }

    // Takes money from the drawer if current denomination is less than change due, and there is money in the corresponding drawer.
    // Increments requisite value in the change array, and decrements it from the cidTotal value.
    if (currencyValue[i] < changeDue && comparisonDrawer[i][1] > 0) {
      transaction.change[i][1] += Math.Round(currencyValue * 100) / 100;
      cidTotal -= Math.Round(currencyValue * 100) / 100;
    }


    if (i === 9) {
        transaction.status = "INSUFFICIENT_FUNDS";
        transaction.change = [];
    }
    if (changeDue === 0) {
      transaction.status = "OPEN";
      transaction.change.reverse();
    }

  }

return transaction;
}

checkCashRegister(19.5, 20,
  [["PENNY", 0.01],
  ["NICKEL", 0],
  ["DIME", 0],
  ["QUARTER", 0],
  ["ONE", 1],
  ["FIVE", 0],
  ["TEN", 0],
  ["TWENTY", 0],
  ["ONE HUNDRED", 0]]);