samedi 3 décembre 2016

if statement not executing inside for loop

Not sure why the if statement inside the second for loop not executing, anyone who can point me in the right direction would be appreciated.

function checkCashRegister(price, cash, cid) {
  var change;
  var balance = [];
  var total = 0;
  for (var i = 0; i<cid.length; i++) {
    total += cid[i][1];
    change = cash - price;  
    if (total < change) {
      return "Insufficient Funds";
    } else if (total === change) {
      return "Closed";
    } 
  }
  for (var x = 8; x >= 0; x--) {
    if (change > cid[x][1] && change <= cid[x][1]) {
      balance.push(cid[x-1][1]);
    }
  }
  return balance;
} //end function

checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME",     3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);

Aucun commentaire:

Enregistrer un commentaire