Build a Cash Register Project

**Can someone tell me whats wrong here, I exactly get the answer that the tests check but it doesn’t pass the challenge **

let cid = [
    /*["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]
    [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]*/
     ["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]
];


console.log("page started")
const input = document.getElementById("cash");
const div = document.getElementById("change-due")
const purchase = document.getElementById("purchase-btn")

const display = (status,payment = [])=>{

    let displayer = `Status: ${status} `
    payment.forEach((pay)=>{
        displayer+=`${pay.join(": $")} `
    })
    div.textContent = displayer
    

}


const ordering=(status,cashes,moneys)=>{
    console.log("Ordering....")
    console.log(cashes)
    const payment = []
    cashes.forEach((x,index)=>x[1]=x[1]*moneys[index])
    cashes.forEach((c)=>{ if(c[1] !== 0){payment.push(c)}})  
    display(status,payment)
}

const getBalanceFromMoney = (status,balance) =>{
    console.log("Getting balance......")
    let amounts = [];
    [...cid].forEach((num)=> amounts.push(Math.ceil(num[1]*100) ))
    amounts = amounts.reverse()
    console.log(amounts)
    const moneys = [100,20,10,5,1,0.25,0.1,0.05,0.01]
    const cashes = [
        ["ONE HUNDRED",0],
        ["TWENTY",0],
        ["TEN",0],
        ["FIVE",0],
        ["ONE",0],
        ["QUATER",0],
        ["DIME",0],
        ["NICKEL",0],
        ["PENNY",0]
    ]

    
    let tempBalance = Math.ceil(balance*100)
    
    moneys.forEach((money,index)=>{
        while(tempBalance >= money*100 && amounts[index] != 0.00*100){
            tempBalance -= money*100
            amounts[index] -= money.toFixed(2)*100
            cashes[index][1] += 1 
            console.log("time",amounts[index],tempBalance,money*100) 
        }
    
    })
    if(tempBalance != 0||tempBalance<0){
        console.log("hi")
        checkBalance(balance = Infinity) 
        return;
    }else{
        amounts = amounts.reverse();
        [...amounts].forEach((c,i)=>cid[i][1]=c/100)
        console.log(amounts,cid)
        ordering(status,cashes,moneys)
    }
    
}



const checkStatus = (balance) =>{
    console.log("Checking....")
    let status = "";
    const balanced_2 = balance.toFixed(2)
    let reduced = 0;
    [...cid].forEach((c)=>reduced+= c[1])
    if(reduced == balanced_2){
        status = "CLOSED"
        getBalanceFromMoney(status,balance)
    }
    if(reduced < balanced_2){
        status = "INSUFFICIENT_FUNDS"
        display(status)
    }
    if(reduced > balanced_2){
        status = "OPEN"
        getBalanceFromMoney(status,balance)
    }
}


const checkBalance = (cash) =>{
    if(cash===price){
        div.textContent = "No change due - customer paid with exact cash"
    }else{
        checkStatus(parseFloat(cash - price))
    }
}

const isCashValid = () => {
    console.log("checking if cash is valid.....")
    const cash = input.value
    cash < price? alert("Customer does not have enough money to purchase the item"): checkBalance(parseFloat(cash))
}

purchase.addEventListener("click",isCashValid)```

Never mind I found the solution I asked chat gpt to debug the code and it gave me the error

Error :

const cashes = [
        ["ONE HUNDRED",0],
        ["TWENTY",0],
        ["TEN",0],
        ["FIVE",0],
        ["ONE",0],
        ["QUATER",0],
        ["DIME",0],
        ["NICKEL",0],
        ["PENNY",0]
    ]

I have typed QUATER insted of QUARTER

an other thing, you need the global price variable, from your code it’s missing

Oh yeah, I might have not included it here but it was in my original code :slight_smile: