Cash Register Solution Error

Hi, guys!
I learn this step: freeCodeCamp Challenge Guide: Cash Register

And solution at this article doesn’t get right answer for some cases.

Please test

checkCashRegister(19.7, 20.0, [
  ["PENNY", 0.02],
  ["NICKEL", 0.0],
  ["DIME", 0.3],
  ["QUARTER", 0.75],
  ["ONE", 0.0],
  ["FIVE", 0.0],
  ["TEN", 0.0],
  ["TWENTY", 0.0],
  ["ONE HUNDRED", 0.0]
]);
1 Like

Can you please provide more details about what errors you are encountering with the sample solution? I would assume with that the drawer shouldn’t be able to make change. (Edit, woops, misread .7 as .97 for some reason) (Though, this is not one of the covered test cases)

Hi!
I expects result
{status: "OPEN", change: [["DIME", 0.3]]}

But article solution returns
{status: "INSUFFICIENT_FUNDS", change: Array(0)}

Ah, yeah. I’d guess that is an intentional gap in the test suite to reduce the complexity of the project.

Okay.
So let it be.
I think the reason is that quarter is not entirely divisible by dimes.
And with all other values it is like this: a larger value contains an integer number of smaller values.

Yep, that’s exactly what’s going on. Retrying which a smaller coin isn’t too hard, but it adds complexity.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.