[ The freeCodeCamp Forum ](/)

#  [ Build a Cash Register project, 1 test to pass! ](/t/build-a-cash-
register-project-1-test-to-pass/685159)

[ JavaScript  ](/c/javascript/421)

[ eusebieDev  ](https://forum.freecodecamp.org/u/eusebieDev) April 13, 2024,
12:11am  1

Hi, after… um, quite a fun time trying to get my final test to pass, I am here
to get some assistance. I may have intense tunnel vision at the moment, as
I’ve been running this in the fCC browser, and a copy in VS Code. I’ve
rummaged all the related topics I can muster at this point. ( i miss pair
programming ![:upside_down_face:](https://emoji.discourse-
cdn.com/twitter/upside_down_face.png?v=12) )

The only test not passing is:  
When ` price ` is ` 3.26 ` , the value in the ` #cash ` element is ` 100 ` , `
cid ` is ` [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER",
4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED",
100]] ` , and the ` #purchase-btn ` element is clicked, the value in the `
#change-due ` element should be ` "Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15
ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04" ` .  
My console shows test complete, but the status message displayed is:  
“Status: OPEN TWENTY: $96.80” . I believe my calculations are working, I just
can’t seem to to print the right status.  
Very Simple HMTL:

    
    
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>fCC Cash Register</title>
        <link rel="stylesheet" href="./styles.css" />
      </head>
      <body>
        <main>
          <h3>freeCodeCamp Cash Register Certification Project</h3>
          <div id="change-due"></div>
          <label for="cash">Amount Tendered:</label>
          <input id="cash" type="number" val="" />
          <button id="purchase-btn">Purchase</button>
        </main>
        <script src="./script.js"></script>
      </body>
    </html>
    

JS:

    
    
    let price = 3.26;
    
    let cid = [
      ["PENNY", 1.01],
      ["NICKEL", 2.05],
      ["DIME", 3.1],
      ["QUARTER", 4.25],
      ["ONE", 90],
      ["FIVE", 55],
      ["TEN", 20],
      ["TWENTY", 60],
      ["ONE HUNDRED", 100],
    ];
    
    document.getElementById("purchase-btn").addEventListener("click", () => {
      const cashProvided = document.getElementById("cash").value;
    
      function calculateChange(changeDue, maxChangePerDenomination) {
        const denominations = [
          ["ONE HUNDRED", 100],
          ["TWENTY", 20],
          ["TEN", 10],
          ["FIVE", 5],
          ["ONE", 1],
          ["QUARTER", 0.25],
          ["DIME", 0.1],
          ["NICKEL", 0.05],
          ["PENNY", 0.01],
        ];
        const maxChangeCopy = { ...maxChangePerDenomination };
        let change = [];
        for (let i = 0; i < denominations.length; i++) {
          const [denomination, value] = denominations[i];
          if (changeDue >= value && maxChangeCopy[denomination] > 0) {
            const amountToReturn = Math.min(
              changeDue / value,
              maxChangePerDenomination[denomination] 
            ).toFixed(2);
    
            // Check for available bills and adjust as needed
            const availableBills = Math.floor(maxChangeCopy[denomination]);
            const actualAmountToReturn = Math.min(amountToReturn, availableBills);
            const amountReturned = parseFloat(actualAmountToReturn) * value;
            change.push([denomination, amountReturned]);
            changeDue -= amountReturned;
            // Update maxChangeCopy with actual bills used
            maxChangeCopy[denomination] -= actualAmountToReturn;
          }
        }
        if (changeDue <= 0) {
          return change;
        }
        return [];
      }
      const totalCID = cid.reduce((acc, [, val]) => acc + val, 0);
      let changeDue = Math.round((cashProvided - price) * 100) / 100;
      if (cashProvi