### Tell us what’s happening:

Please help if you can! I have this code working *almost*, but for some reason it does not give the last penny in change! Can anyone explain why this is? I have been using pythontutor.com and everything goes fine, but when it gets to this block of code:

```
let funkyCid = cid.reverse();
for(let i = 0; i < funkyCid.length; i++){
if(change - funkyMoney[i] >= 0 && funkyCid[i][1] - funkyMoney[i] >= 0) {
while(funkyCid[i][1] - funkyMoney[i] >= 0 && change - funkyMoney[i]>= 0){
funkyCount[i] += 1;
change -= funkyMoney[i];
funkyCid[i][1] -= funkyMoney[i];
}
}
```

it will not stay in the while loop one more time in order to give the last penny in change. Then the rest of it executes and it dishes out the correct change, except for that last penny.

I am sure this code is overcomplicated but it is the way I could figure it out step by step.

Any help or insight would be greatly appreciated! Two weeks working on this code and I am just very stuck.

### Here is my huge code so far:

```
function checkCashRegister(price, cash, cid) {
let change = cash - price;
let sum = 0;
for(let i = 0; i < cid.length; i++) {
sum += cid[i][1];
}
let funkyMoney = [ 100, 20, 10, 5, 1, .25, .10, .05, .01]
let funkyCount = [0, 0 ,0 ,0 ,0 ,0 ,0 ,0, 0]
if(change < 0 || sum - change < 0) {
return {status: "INSUFFICIENT_FUNDS", change: []};
} else if(change === sum) {
return {status: 'CLOSED', change: [cid]};
} else if(change > 0) {
let funkyCid = cid.reverse();
for(let i = 0; i < funkyCid.length; i++){
if(change - funkyMoney[i] >= 0 && funkyCid[i][1] - funkyMoney[i] >= 0) {
while(funkyCid[i][1] - funkyMoney[i] >= 0 && change - funkyMoney[i]>= 0){
funkyCount[i] += 1;
change -= funkyMoney[i];
funkyCid[i][1] -= funkyMoney[i];
}
}
}
let changer2 = [];
function funkie(arr1, arr2) {
for(let i = 0; i < arr1.length; i++) {
changer2.push(arr1[i] * arr2[i])
}
}
funkie(funkyMoney, funkyCount);
let funkyChangeReturned = [];
let currencyFunky = [
["ONE HUNDRED", 0],
["TWENTY", 0],
["TEN", 0],
["FIVE", 0],
["ONE", 0],
["QUARTER", 0],
["DIME", 0],
["NICKEL", 0],
["PENNY", 0]
];
for(let i = 0; i < changer2.length; i++) {
currencyFunky[i][1] = changer2[i];
}
for(let i = 0; i < currencyFunky.length; i++) {
if(currencyFunky[i][1] !== 0) {
funkyChangeReturned.push(currencyFunky[i]);
}
}
return { status: "OPEN", change: funkyChangeReturned};
}
}
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]]);
```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`

### Challenge Information:

JavaScript Algorithms and Data Structures Projects - Cash Register