# Exact Change - Help

**URL:** <https://forum.freecodecamp.org/t/exact-change-help/104075>\
**Category:** General\
**Created:** [April 7, 2017, 10:30pm UTC](https://forum.freecodecamp.org/t/exact-change-help/104075 "2017-04-07T22:30:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kylefujisawa](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@kylefujisawa](https://forum.freecodecamp.org/u/kylefujisawa)\
**Post date:** [April 7, 2017, 10:30pm UTC](https://forum.freecodecamp.org/t/exact-change-help/104075/1 "2017-04-07T22:30:32Z")

</div>

Hi FCC Community!

I’m having an issue with the Front End Developer Advanced Algorithm Scripting Challenge - Exact Change. I believe that I came up with a working solution, but I can’t get it to pass. I know that it’s not exact: my output is [[“QUARTER”,0.5]] instead of [[“QUARTER”, 0.50]], but after hours of trying to get a 0.50 format, I’ve looked at the other threads and other campers have said it’s not necessary to make the output 0.5 vs. 0.50. So now that that’s not the issue, I don’t know how else to debug this. Could someone give me some tips on how to further debug my code? Are there some errors I am not seeing? Thank you!

```auto
//set values for each currency
var currencyWorth = {
  "PENNY": 0.01,
  "NICKEL": 0.05,
  "DIME": 0.10,
  "QUARTER": 0.25,
  "ONE": 1.00,
  "FIVE": 5.00,
  "TEN": 10.00,
  "TWENTY": 20.00,
  "ONE HUNDRED": 100.00
};

var changeArr = [];

function checkCashRegister(price, cash, cid) {
  //calculate change due
  var change = cash - price;
  change = Math.round(change *100)/100;
  
  //total up cash in drawer
  var cashMoney = cid.reduce(function (acc, next) {
    return acc + next[1];
  }, 0.0);
  
  //check if we don't have enough or if exactly enough.
  if (cashMoney < change){
    console.log("IF");
    return "Insufficient Funds";
  } else if (cashMoney == change){
    console.log('closed');
    return "Closed";
  } 
  
  
  var count=0.0;
  //iterate through cid amounts. decrement the change by the bill/coin's worth and keep a 'count' for each bill/coin which is pushed onto a result array.
  for (i = cid.length - 1; i >= 0; i --){
    
    var moneyType = cid[i][0];
    var drawerVal = cid[i][1];
   
    while (change >= currencyWorth[moneyType] && drawerVal >= currencyWorth[moneyType]){
          
      //keep track of current highest bill/coin amount used
      count += currencyWorth[moneyType];
      count = Math.round(count*100)/100;

      //decrement 'change'
      change -= currencyWorth[moneyType];
      change = Math.round(change*100)/100;
      
      //decrement from cid
      drawerVal -= currencyWorth[moneyType];
      drawerVal = Math.round(drawerVal*100)/100;
      
      //push to result array once bill/coin is now too high or has been used up 
      if(change < currencyWorth[moneyType] || drawerVal === 0) {
          
        changeArr.push([moneyType, count]);
        count = 0.0;
        
      }
      
    }
    
}  
  //if the coins don't match up, there is change left over
  if (change > 0){
    
    return 'Insufficient Funds';
    
  }
  
  return changeArr;
  
}
  

checkCashRegister(19.50, 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]]);

```

---

<div class="post-metadata">

**Author:** ![kylefujisawa](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@kylefujisawa](https://forum.freecodecamp.org/u/kylefujisawa)\
**Post date:** [April 7, 2017, 11:04pm UTC](https://forum.freecodecamp.org/t/exact-change-help/104075/3 "2017-04-07T23:04:41Z")

</div>

@rmdawson71 Wow, thanks for the help! 😁 I don’t understand that at all. Do you have further explanation?

---

<div class="post-metadata">

**Author:** ![kylefujisawa](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@kylefujisawa](https://forum.freecodecamp.org/u/kylefujisawa)\
**Post date:** [April 7, 2017, 11:41pm UTC](https://forum.freecodecamp.org/t/exact-change-help/104075/5 "2017-04-07T23:41:53Z")

</div>

Awesome! That makes a lot of sense now. Thanks so much for getting back to me! Very helpful! 😀

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 9:37am UTC](https://forum.freecodecamp.org/t/exact-change-help/104075/6 "2021-01-17T09:37:36Z")

</div>


