Cash Registry Should be Working

I dont know way this is not working the functions seem to be working


var changeToCustomer;
var changeDue;
var currentCoinCount = 0;
var currentCoinLimit = 0;
var singleValue;
var minimumIncrement;
var remainder;
var remainder2;
var remainderfixed;
var finalarray=[];
var thisremainder;
var justNamesAndValue = [
 ["PENNY", 0],
 ["NICKEL", 0],
 ["DIME", 0],
 ["QUARTER", 0],
 ["ONE", 0],
 ["FIVE", 0],
 ["TEN", 0],
 ["TWENTY", 0],
 ["ONE HUNDRED", 0]
];

var finalStatusArray = [];
var finalStatus = {
 status: "",
 change:[]
};

function checkCashRegister(price, cash, cid) {
  changeToCustomer = cash - price;
  changeDue = cash - price;
 var justValues = [];
 for (var i = 0; i < cid.length; i++) {
  justValues.push(cid[i][1]);

 }


 const reducer = (accumulator, currentValue) => accumulator + currentValue;
 (justValues.reduce(reducer));

 





 var newRegister = [0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 100];
 for (var i = 0; i < cid.length; i++) {
  cid[i][2] = newRegister[i];
  cid[i][3] = 0;
 }


 //console.log(cid);

 //so cid has been transformed into say ["PENNY",0.5,0.01]

 function findChange(cid, finalStatus) {


 let res = cid.reduce((total,currentValue) => {
return total + currentValue[1];
},0);

singleValue = res.toFixed(2);
//console.log(singleValue)

 //FOR EACH DENOMINATION IN THE ARRAY
 
  for (var j = cid.length-1; j>-1; j--) {
    currentCoinLimit=cid[j][1];
   minimumIncrement = cid[j][2];
    
   // THE IF CONDITION BELOW
   //DETERMINES WHERE TO START IN THE ARRAY SO ONLY START IF THE MINIMUM INCREMENT
   // IS LESS THEN THE CHANGE DUE
    

     if(minimumIncrement<=changeToCustomer){
       if(changeToCustomer>currentCoinLimit){
  // SO WE JUST TAKE ALL THE AVAILABLE COINS FROM THIS COIN TYPE AS LONG AS THE TOTAL IS LESS THEN THE CHANGE DUE
  // ONLY DIFFERENCE BETWEEN THIS SECTION AND THE SECTION UNDER ELSE IS THE IF   //       //CONDITION ABOVE and THE currentCoinLimit BELOW INSTEAD OF changeToCustomer       
         remainder = currentCoinLimit/minimumIncrement;
         remainderfixed = remainder.toFixed(2);
         thisremainder = parseInt(remainder);
         remainder2=thisremainder*minimumIncrement;
         console.log("1st section",changeToCustomer)
         changeToCustomer=changeToCustomer-remainder2;//WHATS LEFT OVER BECOMES THE NEW ChangeToCustomer
         cid[j][3]=remainder2;
         var finalarrayj =[];
         if(cid[j][3]!=0){
         finalarrayj.push(cid[j][0],cid[j][3]);
         console.log("1st section",cid[j][3])
         finalarray.push(finalarrayj);
         }
       }
       else{
      console.log("2nd section",changeToCustomer)
       remainder=changeToCustomer/minimumIncrement;
       remainderfixed = remainder.toFixed(2);
       thisremainder=parseInt(remainderfixed);
       remainder2=thisremainder*minimumIncrement;
       changeToCustomer=changeToCustomer-remainder2;
       cid[j][3]=remainder2;
       var finalarrayj =[];
       if(cid[j][3]!=0){
       finalarrayj.push(cid[j][0],cid[j][3]);
       console.log("2nd section",cid[j][3])
       finalarray.push(finalarrayj);
       }
       }
     }

  }
 }
 

   findChange(cid, finalStatus);
  //console.log(cid)
  //console.log(cid)
   
if(singleValue<changeDue){
  
  finalStatus.status="INSUFFICIENT FUNDS";
   finalStatus.change=finalarray;
}


else if(changeDue===singleValue){
  finalStatus.status="closed";
  finalStatus.change=finalarray;
}
else{
  
    finalStatus.status="OPEN"
    finalStatus.change=finalarray;
  
}

console.log(finalStatus.status)
console.log(finalStatus.change)

return finalStatus;
  }

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 code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2