Help with JavaScript Cash Register Challenger

Need Help finishing this challenge. I can get all the test to solve for the cash register challenge in the JavaScript Legacy Certification curriculum, except for test 3. I tried looking for help, ask some friends, re-set the tests and even tried using AI to debug the code. Nothing seems to be working. Any ideas will be helpful and appreciated!

function checkCashRegister(price, cash, cid) {
  // Define the currency units and their values in descending order
  const currencyUnitValues = [
    ["ONE HUNDRED", 100],
    ["TWENTY", 20],
    ["TEN", 10],
    ["FIVE", 5],
    ["ONE", 1],
    ["QUARTER", 0.25],
    ["DIME", 0.1],
    ["NICKEL", 0.05],
    ["PENNY", 0.01]
  ];

  // Calculate the total change to return
  let changeDue = cash - price;
  let change = [];
  let totalCid = 0;
  
  // Calculate the total cash in the drawer
  for (let i = 0; i < cid.length; i++) {
    totalCid += cid[i][1];
  }

  // Round to two decimal places for accuracy when working with currency
  changeDue = Math.round(changeDue * 100) / 100;
  totalCid = Math.round(totalCid * 100) / 100;

  // Check if we have enough cash in the drawer
  if (totalCid < changeDue) {
    return { status: "INSUFFICIENT_FUNDS", change: [] };
  }

  // Check if the drawer has the exact change
  if (totalCid === changeDue) {
    return { status: "CLOSED", change: cid };
  }

  // Process the change due from the cash-in-drawer
  for (let i = 0; i < currencyUnitValues.length; i++) {
    const [unit, value] = currencyUnitValues[i];
    let amountInDrawer = cid[i][1];
    let amountToReturn = 0;

    // Calculate the amount to return for the current currency unit
    while (changeDue >= value && amountInDrawer > 0) {
      changeDue = Math.round((changeDue - value) * 100) / 100;
      amountInDrawer = Math.round(amountInDrawer * 100) / 100;
      amountToReturn += value;
    }

    // If we return some change, update the drawer and change array
    if (amountToReturn > 0) {
      change.push([unit, amountToReturn]);
      cid[i][1] -= amountToReturn;
    }

    // If the change due has been resolved, stop the loop
    if (changeDue === 0) break;
  }

  // Check if we were able to return the exact change
  if (changeDue > 0) {
    return { status: "INSUFFICIENT_FUNDS", change: [] };
  }

  // If there is still money left in the drawer, return OPEN status
  return { status: "OPEN", change: change };
}

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Have you looked at the returned result for that test case? I’m getting:

{ status: 'OPEN',
  change: 
   [ [ 'TWENTY', 80 ],
     [ 'TEN', 10 ],
     [ 'FIVE', 5 ],
     [ 'ONE', 1 ],
     [ 'QUARTER', 0.5 ],
     [ 'DIME', 0.2 ],
     [ 'PENNY', 0.04 ] ] }

But the cash register in this case does not have 80 in dollars in twenties.

Oh I see! There is a computation and maybe even a rounding error. Thank you for advice! Now at least I have a starting point to look more closely at and figure it out.