Cash Register Frustration

For the final check my code produces the result:
{status: “CLOSED”, change: [[“PENNY”, 0.5]]}

The official result should be:
{status: “CLOSED”, change: [[“PENNY”, 0.5], [“NICKEL”, 0], [“DIME”, 0], [“QUARTER”, 0], [“ONE”, 0], [“FIVE”, 0], [“TEN”, 0], [“TWENTY”, 0], [“ONE HUNDRED”, 0]]}

I don’t understand why in the last problem it’s expected to return results for unused denominations (in reverse order none the less), but in all the other cases only the denominations that are used show in the change array and are in order from large to small.

Can anyone explain why this is wrong according to the directions and requirements of the problem?

Personally, I feel like the wording for this problem should be updated to reflect the expected solutions, or allow multiple correct answers.

Thanks

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register

To quote from that page:

Return {status: "CLOSED", change: [...]} with cash-in-drawer as the value for the key change if it is equal to the change due.

Thus, if the actual amount of cash in the drawer is equal in value to the change due, you won’t be doing ANY processing of “which unit of change do I need?” You simply return status: "CLOSED" and cash-in-drawer (or cid) exactly as it is passed to you.

1 Like

Thanks for the explanation. Your stating not to do “ANY processing” clicks with me and makes sense when I think about saving on computer processing. I was running every scenario through a while statement and then throwing the conditional at the end to determine the status and return the object. In my head I read “cash-in-drawer” and began literally thinking in the sense of physical money rather than the original array provided.

Again, thanks, I appreciate your interpretation!

1 Like

Its a minor thing, but definitely a gotcha. Also very similar to actual client use cases. :slight_smile: