Build a Cash Register Project - Build a Cash Register

Tell us what’s happening:

my code passes all tasks except last 2 please help

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <input id="cash">
  <div id="change-due"></div>
  <button id="purchase-btn">Sale</button>
    <script src="./script.js"></script>
</body>
</html>
/* file: styles.css */

/* file: script.js */

let price = 19.5;
let cid = [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]];

const cash=document.getElementById("cash")
const change=document.getElementById("change-due")
const sale=document.getElementById("purchase-btn")

let currencyUnits= [
  ["PENNY", .01],
  ["NICKEL", .05],
  ["DIME", .1],
  ["QUARTER", .25],
  ["ONE", 1],
  ["FIVE", 5],
  ["TEN", 10],
  ["TWENTY", 20],
  ["ONE HUNDRED", 100]
];

sale.addEventListener("click",()=>{
  const cashValue=parseFloat(cash.value);
  const changeDue=cashValue-price;

  if(cashValue<price){
    alert("Customer does not have enough money to purchase the item");
    return;
  }

  if (cashValue === price){
    change.innerText="No change due - customer paid with exact cash"
    return;
  }
  const changeResult = getChange(changeDue, cid);

  if(changeResult.status==="INSUFFICIENT_FUNDS" ||changeResult.status==="CLOSED" ){
    change.innerText=`Status: ${changeResult.status} ${formatChange(changeResult.change)}`
  }
  else  {
    let changeText=`Status: OPEN ${formatChange(changeResult.change)}`
    change.innerText = changeText.trim()
     }

});
const getChange=(changeDue, cid)=>{
  let totalCid =parseFloat(cid.reduce((sum,[_,amount])=>sum+amount,0).toFixed(2));

  if(totalCid<changeDue){
    return {status:"INSUFFICIENT_FUNDS", change: [] }
  }

  let changeArray=[];
  let remainingChange=changeDue;

  for (let i=currencyUnits.length-1;i>=0;i--){
    let unit=currencyUnits[i][0];
    let unitValue = currencyUnits[i][1];
    let unitInDrawer = cid[i][1];

if (unitValue <= remainingChange && unitInDrawer>0){
  let amountFromUnit=0;
  while (remainingChange >= unitValue && unitInDrawer>0 ){
    remainingChange=(remainingChange-unitValue).toFixed(2);
    unitInDrawer-=unitValue;
    amountFromUnit+=unitValue;
  }

  if (amountFromUnit>0){
    changeArray.push([unit, amountFromUnit])
  }
}
  }//end of for loop
  if (remainingChange > 0){
    return { status: "INSUFFICIENT_FUNDS", change: [] }
  }
  if (changeDue === totalCid){
    return { status: "CLOSED", change: cid }
  }

  return { status: "OPEN" , change: changeArray }
  
}//get change end

const formatChange = changeArray=>changeArray.map(([unit,amount])=>`${unit}: $${amount.toFixed(2)}`).join(" ")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Build a Cash Register Project - Build a Cash Register

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

This challenge is still bugged. You should wait for the fix.


This PR

https://github.com/freeCodeCamp/freeCodeCamp/pull/55364

Needs to be on the prod-current branch.

https://github.com/freeCodeCamp/freeCodeCamp/commits/prod-current/

i try to run my code and i pass all checkpoints/tasks in the challenge except for the last 2 checkpoints, i dont know whats the problem,
would appreciate any help

what do you mean bugged?
so you’re saying the problem isnt in my code but in the challege?
in this case is there anything i can do?

You have to wait. If you open the browser console, you can see a reference error to a function used by the tests.

oh ok thanks

btw how can we report the bug?

the bug is reported and solved, you just need to wait for it to be deployed

Ok,
Thank you kindly