Cash Registry Strange Problems with last 3 tests

So all the tests work except the last two,also the third from bottom,works while the one under it doesn’t even though they have the same tests.
Here is a screen shot of the issue.!

Please could someone offer some advice on this problem,and also the problem of the last two failed tests,thank you!

Can you show (paste) your code? That will make helping you easier.


function checkCashRegister(price, cash, cid) {

var finalStatusArray = [];

var finalStatus = {

 status: "",

 change:[]

};

var changeToCustomer;

var currentchange = 0;

var changeDue;

var multiplierOfCoin = 0;

var finalCoinNumber = 0;

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]

];

  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]

 let res = cid.reduce((total,currentValue) => {

return total + currentValue[1];

},0);

singleValue = res.toFixed(2);

//console.log(singleValue)

if(singleValue<changeDue){

  

  finalStatus.status="INSUFFICIENT_FUNDS";

  return finalStatus;

}

 if(changeDue===singleValue){

  finalStatus.status="CLOSED";

  finalStatus.change=finalarray;

  console.log(finalStatus.change,"g")

  return finalStatus;

}

 

  for (var j = cid.length-1; j>-1; j--) {

    currentCoinLimit=cid[j][1];

   minimumIncrement = cid[j][2];

           

     if(minimumIncrement<=changeToCustomer){

       if(changeToCustomer>currentCoinLimit){

         remainder = currentCoinLimit/minimumIncrement;

         remainderfixed = remainder.toFixed(2);

         thisremainder = parseInt(remainder);

         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]);

         finalarray.push(finalarrayj);

         }

       }

       else{

       remainder=changeToCustomer/minimumIncrement;

       //console.log(remainder)

       remainderfixed = remainder.toFixed(2);

       thisremainder=parseInt(remainderfixed);

       //console.log(thisremainder);

       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]);

       finalarray.push(finalarrayj);

       }

       }

     }

  }

  
     

//if{

  

    finalStatus.status="OPEN"

    finalStatus.change=finalarray;

  

//}

console.log(finalStatus.status)

console.log(finalStatus.change)

return finalStatus;

  }

checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])

Third from the bottom and second test differ in one dollar.

To point you to the right direction - what would happen if you have i.e. only one hundred dollar bill, but are supposed to give 20 dollar change?

Second hint is to take a closer look at the condition in case where status is supposed to return "CLOSED".


 if(changeDue==singleValue){

  finalStatus.status="CLOSED";

  finalStatus.change=cid;

 
  return finalStatus;

}

Now it works.
So change it from three = signs to two,and changed the finalStatus to equal cid also put the block as high up the code as possible will now try to work one the other test.

SO IT WORKS NOW ON THIS IS THE FINAL CODE.

function checkCashRegister(price, cash, cid) {

var finalStatusArray = [];
var finalStatus = {
 status: "",
 change:[]
};
var changeToCustomer;
var currentchange = 0;
var changeDue;
var multiplierOfCoin = 0;
var finalCoinNumber = 0;
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]
];

  changeToCustomer = cash - price;
  changeDue = cash - price;

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

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

if(changeDue==singleValue){
  finalStatus.status="CLOSED";
  finalStatus.change=cid;
  return finalStatus;
}

 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]

if(singleValue<changeDue){
  
  finalStatus.status="INSUFFICIENT_FUNDS";
  finalStatus.change=finalarray;
  return finalStatus;
}

  for (var j = cid.length-1; j>-1; j--) {
    currentCoinLimit=cid[j][1];
   minimumIncrement = cid[j][2];
    
     if(minimumIncrement<=changeToCustomer){
       //first if tells you which denomination to start from
       if(changeToCustomer>currentCoinLimit){
         //second if takes all the denomination of its kind
         // meaning you dont have to divide the demonination
         // ie all of the currentCoinLimit
         remainder = currentCoinLimit/minimumIncrement;
         remainderfixed = remainder.toFixed(2);
         thisremainder = parseInt(remainder);
         remainder2=thisremainder*minimumIncrement;
         changeToCustomer=(changeToCustomer-remainder2).toFixed(2);
         cid[j][3]=remainder2;
         var finalarrayj =[];
         //console.log(cid[j][0],changeToCustomer);
         if(cid[j][3]!=0){
         finalarrayj.push(cid[j][0],cid[j][3]);
         finalarray.push(finalarrayj);
         }
       }
       else{
       remainder=changeToCustomer/minimumIncrement;
       remainderfixed = remainder.toFixed(2);
       thisremainder=parseInt(remainderfixed);
       // the code above would fix a problem like how many 5s
       // can you get out of 16.74 which would be 3 
       remainder2=thisremainder*minimumIncrement;
       // 3 times 5 = 15 so taking the example how much you could 
       // take from 16.74 you could take 15 from 16 leaving 1.74
       changeToCustomer=(changeToCustomer-remainder2).toFixed(2);
       cid[j][3]=remainder2;
       var finalarrayj =[];
       if(cid[j][3]!=0){
       finalarrayj.push(cid[j][0],cid[j][3]);
       finalarray.push(finalarrayj);
       
       
       }
       
       }
      
     }


  }
  console.log(changeToCustomer);
  

  **if(changeToCustomer>0.00){**
**  finalStatus.status="INSUFFICIENT_FUNDS";**
**  finalStatus.change=[];**
**  return finalStatus; **
**  }**
  
finalStatus.status="OPEN"
finalStatus.change=finalarray;  

  return finalStatus;
  
  }

checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])
**strong text**