# Exact Change Frustration

**URL:** <https://forum.freecodecamp.org/t/exact-change-frustration/67515>\
**Category:** General\
**Created:** [December 20, 2016, 4:28pm UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515 "2016-12-20T16:28:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![francismaile](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/francismaile/32/164075_2.png) [@francismaile](https://forum.freecodecamp.org/u/francismaile)\
**Post date:** [December 20, 2016, 4:28pm UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/1 "2016-12-20T16:28:54Z")

</div>

Hi All,

Struggling with the Exact Change challenge.

When I run my code, I get the right answers. In fact, I get the same answer as when I run the solution provided by this forum in the Algorithms section.

Here is my code:

```auto
var denominations = [
  { name: 'ONE HUNDRED', value: 100 },
  { name: 'TWENTY', value: 20 },
  { name: 'TEN', value: 10 },
  { name: 'FIVE', value: 5 },
  { name: 'ONE', value: 1 },
  { name: 'QUARTER', value: 0.25 },
  { name: 'DIME', value: 0.10 },
  { name: 'NICKEL', value: 0.05 },
  { name: 'PENNY', value: 0.01 }
];

function checkCashRegister(price, cash, cid) {
  var changeDue = cash - price;
  var changeGiven = 0;
  var changeArray = [];

  var drawer = cid.reduce(function(acc, curr) {
    acc.total += curr[1];
    acc[curr[0]] = curr[1];
    return acc;
  }, {total: 0});
  drawer.total = Math.round(drawer.total * Math.pow(10,2)) / Math.pow(10,2);

  if( drawer.total - changeDue < 0 ) {
    return "Insufficient Funds";
  } else if( drawer.total - changeDue === 0 ) {
    return "Closed";
  } else {
      denominations.forEach(function(denom) {
        while( changeDue >= denom.value && drawer[denom.name] > 0 ) {
          drawer[denom.name] -= denom.value;
          changeDue -= denom.value;
          changeDue = Math.round(changeDue * Math.pow(10,2)) / Math.pow(10,2);
          changeGiven += denom.value;
        }
        if( changeGiven > 0 ) {
          changeArray.push([denom.name,changeGiven]);
          changeGiven = 0;
        }
      });
  }

  // Here is your change, ma'am.
  return changeArray;
}

```

Somebody please…

---

<div class="post-metadata">

**Author:** ![anon97231988](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon97231988](https://forum.freecodecamp.org/u/anon97231988)\
**Post date:** [December 20, 2016, 4:34pm UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/2 "2016-12-20T16:34:19Z")

</div>

> [@francismaile](#):
>
> When I run my code, I get the right answers. In fact, I get the same answer as when I run the solution provided by this forum in the Algorithms section.

Ok, I’d say that’s good. Where is the frustration part?

---

<div class="post-metadata">

**Author:** ![francismaile](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/francismaile/32/164075_2.png) [@francismaile](https://forum.freecodecamp.org/u/francismaile)\
**Post date:** [December 20, 2016, 4:45pm UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/3 "2016-12-20T16:45:56Z")

</div>

I was unclear. When I ran it in my browser on my local server I got the same result but when I ran it in FreeCodeCamp I didn’t get the correct result.

The solution was really simple, actually. I don’t know why I didn’t see it sooner. I changed all the single quotes to double quotes in the denominations declaration and that cleared the problem.

Thanks for checking in though.

---

<div class="post-metadata">

**Author:** ![phoenixVictoria](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/phoenixvictoria/32/19893_2.png) [@phoenixVictoria](https://forum.freecodecamp.org/u/phoenixVictoria)\
**Post date:** [December 21, 2016, 7:58am UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/4 "2016-12-21T07:58:19Z")

</div>

Hey, there seems to be an issue with the second to the last use case. the amount in the cash register for that use case is greater than the difference between the cash and price so the answer should not be “Insufficient Balance”. Please someone help point out what i m missing?

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [December 21, 2016, 9:15am UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/5 "2016-12-21T09:15:07Z")

</div>

You can’t give a change of 50 cents if all you have is one dollar.

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:11am UTC](https://forum.freecodecamp.org/t/exact-change-frustration/67515/6 "2021-01-16T06:11:02Z")

</div>


