0

I want to do something inside the if statement. But i cant able to do it since one error is coming in the code saying "cannot read property of undefined". I don't understand. How can it not read cid[j][1] as its value is clearly equal to a number stored.

function checkCashRegister(price, cash, cid) {
    let sum=0;
    let change=cash-price;
    let myarr=[];
    for(let i=0;i<cid.length;i++){
      sum=sum+cid[i][1];
    }
    sum=Math.floor(sum*100)/100;

    cid.reverse();
    console.log(cid);

    if(sum>change){
      let arr=[["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]]; 
      for(let j=0;j<=cid.length-1;j++){
        if(change>=cid[j][1] && change<=cid[j+1][1]){

        }
      }
      }
    }

    checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]); 

0 Answers0