Exact Change Frustration

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:

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…

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

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.

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?

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