不确定为什么第二个for循环中的if语句没有执行,任何能指出我正确方向的人都会受到赞赏。
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]]);