The aim of this algorithm is to return an organized array (with currencies) of the change .
I built a nested while loop to loop as long as "change" is not equal 0 then each loop in the while loop function while "change" is more than 0 (i.e : not -ve).
What have I missed?
// function checkCashRegister(price, cash, cid) { var change = cash-price; var chArr = [["PENNY", 0], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]; while (change !== 0) { while (change - 100 > 0) { chArr[8][1] += 100; change -=100; if (change <= 0) {break;} } while (change - 20 > 0) { chArr[7][1] += 20; change -=20; if (change <= 0) {break;} } while (change - 10 > 0) { chArr[6][1] += 10; change -=10; if (change <= 0) {break;} } while (change - 5 > 0) { chArr[5][1] += 5; change -=5; if (change <= 0) {break;} } while (change - 1 > 0) { chArr[4][1] += 1; change -=1; if (change <= 0) {break;} } while (change - 0.25 > 0) { chArr[3][1] += 0.25; change -=0.25; if (change <= 0) {break;} } while (change - 0.1 > 0) { chArr[2][1] += 0.1; change -=0.1; if (change <= 0) {break;} } while (change - 0.05 > 0) { chArr[1][1] += 0.05; change -=0.05; if (change <= 0) {break;} } while (change - 0.01 > 0) { chArr[0][1] += 0.01; change -=0.01; if (change <= 0) {break;} } if (change <= 0) {break;} } // Here is your change, ma'am. return chArr; } checkCashRegister(17.46, 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]]);