Cash Register while loop issue with var

Tell us what’s happening:
Im not sure why in last part of code with my two while loops that chageBack is not adding so the if statement --if (change < changeBack + filt[inc][1])-- pickup changeBack. i check changeBack in bottom of while loops and value is at 135 but on top of while loop is 80. am i headed the right way to solve this or am i messing up my code trying to solve current way? thanks

Your code so far


function checkCashRegister(price, cash, cid) {
const result = {
status : ["INSUFFICIENT_FUNDS","CLOSED","OPEN"],
change : []
}

//Get Change from purchase
const change = cash - price;

//get total of CID values
var x = cid.map((ci)=>{return ci[1]})
var cidTotal = x.reduce((acc, xx)=>{ return Math.round(acc + xx) },0)

//Get total number of each coin CID
let key = {"PENNY" : .01, "NICKEL" : .05, "DIME" : .1, "QUARTER" : .25, "ONE" : 1, "FIVE" : 5, "TEN" : 10, "TWENTY" : 20, "ONE HUNDRED": 100};
let keyR = {"ONE HUNDRED" : 100, "TWENTY" : 20, "TEN" : 10, "FIVE" : 5, "ONE" : 1, "QUARTER" : .25, "DIME" : .10, "NICKEL" : .05, "PENNY": .01};
const keyValues = Object.values(key)
const billName = Object.keys(keyR)
let coins = x.map((cv,i) => Math.round(cv / keyValues[i]))

//check for INSUFFICENT 
if (cidTotal < change){
result.status = "INSUFFICIENT_FUNDS";
return result;
} 
//Check for CLOSED status
if (cidTotal == change){
result.status = "CLOSED"
result.change = cid;
return result;
}

//Check for OPEN status
else{
//Filter key objects to pull value closet to change var and assing to result
  const changeCur = Object.values(key).filter((cur, i) => cur <= change)
  let newArr = []
  cid.reverse()
  keyValues.reverse()
  changeCur.reverse()
  coins.reverse()
let changeBack = 0;
let xx = change
let inc = 0;
let loopKey = keyValues.filter(fi => fi < change)
let filt = cid.filter((cv,i) => cv[1] < change)
let nameReduce = billName.slice(billName.length - filt.length)

while (changeBack < xx){
 
if (change < changeBack + filt[inc][1]){
   let count = 0;
   while (count <= change - changeBack){
      if (count + loopKey[inc] > change - changeBack){
        break;
      }
      count += loopKey[inc]
      //console.log([nameReduce[inc],count])
      //newArr.push([nameReduce[inc],count])
   }
  
   newArr.push([nameReduce[inc],count])
   //filt[inc][1] = count
 changeBack += filt[inc][1]
   inc++;
}
newArr.push(filt[inc])
changeBack += filt[inc][1];
inc++
}
  console.log(newArr)

  result.status = "OPEN";
  return result
}
}
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36.

Challenge: Cash Register

Link to the challenge: