Build a Cash Register Project - Random approval for test #13 and #19

Hi, after all the other test were approved, i noticed that the test #13 sometimes was checked and sometimes not, with the same code, i started spaming a little bit the “Run the test” and the code approved, #13 and #19 was done.
I’m curious why that happens. Here is the code:

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]
];

const divCid = document.getElementById("cid");
const inputCash = document.getElementById("cash");
const purchaseBtn = document.getElementById("purchase-btn");
const divChange = document.getElementById("change-due");
const pPrice = document.getElementById("price");
divCid.textContent = cid
const price = 19.5;
pPrice.textContent = `Price: $${price}`;

class Register {
  constructor(){
    this.amountWorthChange = [[0,0,0,0,0,0,0,0,0],[1,5,10,50,100,500,1000,2000,10000],[0,0,0,0,0,0,0,0,0]]
  };

 calculateAmount() {
   cid = cid.map((subArray) => [subArray[0],subArray[1]*100])

  this.amountWorthChange[0] = this.amountWorthChange[1].map((worth, i) => cid[i][1]/worth);
  }


  change() {
    return parseFloat(inputCash.value) - price;
  };

  calculateChangeDisponibility(){
    this.calculateAmount()
    let change = change()*100;
    for (let i = 8; i > -1; i--) {
      while(change >= this.amountWorthChange[1][i] && this.amountWorthChange[0][i] > 0) {
        change -= this.amountWorthChange[1][i];
        this.amountWorthChange[0][i] --;
        this.amountWorthChange[2][i] += this.amountWorthChange[1][i];
      };
    };
    return change
  };

  options() {

    const cidSum = cid.reduce((acc, subArray) => acc + subArray[1], 0);

    const changeDisponibility = !this.calculateChangeDisponibility();

    const cash = parseFloat(inputCash.value)

    if(price > cash) {
      alert("Customer does not have enough money to purchase the item")
    }

    else if(price === cash) {
      divChange.innerHTML = "No change due - customer paid with exact cash"
    }

    else if(cidSum === this.change() && price < cash && changeDisponibility && this.amountWorthChange[0].every(number => number===0)){
        this.updateClosedText()
        this.updateCid()
        divCid.textContent = cid
    }

    else if(cidSum > this.change() && price < cash && changeDisponibility){
       this.updateText()
       this.updateCid()
       divCid.textContent = cid
    }

    else if(!changeDisponibility){
      divChange.innerHTML = "Status: INSUFFICIENT_FUNDS"
    }
    this.resetAmountChangeArray() 
    inputCash.value = ""
    
  }

  resetAmountChangeArray() {
  this.amountWorthChange[2] = this.amountWorthChange[2].map(() => 0);
  this.amountWorthChange[0] = this.amountWorthChange[0].map(() => 0);

}

  updateText() {
    let text = "Status: OPEN"
    for (let i = 8; i > -1; i--) {
      if(this.amountWorthChange[2][i] > 0) {
        text += `</br>${cid[i][0]}: $${this.amountWorthChange[2][i]/100}`
      }
    }
    return divChange.innerHTML = text
  }

  updateClosedText() {
    let text = "Status: CLOSED"
    for (let i = 8; i > -1; i--) {
      if(this.amountWorthChange[2][i] > 0) {
        text += `</br>${cid[i][0]}: $${this.amountWorthChange[2][i]/100}`
      }
    }
    return divChange.innerHTML = text
  }

  updateCid() {
  cid = cid.map((subArray, i) => [subArray[0], (subArray[1] - this.amountWorthChange[2][i]) / 100]);
}

};

const register = new Register

purchaseBtn.addEventListener("click", () => register.options())

those two are random, if your code doesn’t pass them sometimes you probably have a floating point issue somewhere

how do you deal with the issue that operation with decimals are terribly unprecise?
0.1 + 0.2 results in 0.30000000000000004

multiplication and division is worse than that

I’m trying to identify every time a operation with decimals ocurrs and aply math.round(x*100)/100. In teory if i cover all the decimal operations i shouldn’t have any problem right?

you don’t need to do it at all operations, you can multiply by 100 as first thing, and divide by 100 as last thing before giving the output

Thanks! i’m done!, also i was using a worth of “$0.5” for quarter instead of “$0.25”.