JavaScript: Cash Register - wrong test assertion

JavaScript: Cash Register - wrong test assertion
0

#1

Last test case:
This is incorrect:
{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}

Should be:
{status: "CLOSED", change: [["PENNY", 0.5]]}


#2

The instructions state:

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

You must return the cash-in-drawer, which means you have to return an array with sub arrays for each denomination regardless if they have a zero value. That is why the test expects the array you think is incorrect.

This makes sense, because the cash-in-drawer is passed to the function as the third argument and it includes denominations which also have zero value.

The tests used to validate your return value expect all of the denominations to be present in the final array, so you have no choice about including them or not. You must include them.


#3

Then you have incorrect assertions in all ‘OPEN’ cases as they do not require all of the denominations


#4

The challenge wants you to take care of three circumstances.

  1. When you have enough money to give back the change and have money left in your drawer
    even after paying the change.

For this instructions say,

Return {status: "OPEN", change: [...]} , with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.

  1. When total money in your drawer is equal to amount you have to pay in change.

Instructions in the challenge say following for it.

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

  1. And,finally, when cash in your drawer is not enough to pay the change.

This is instruction for that:

Return {status: "INSUFFICIENT_FUNDS", change: []} if cash-in-drawer is less than the change due, or if you cannot return the exact change.

Does that clear your confusion?


#5

Changing the type of output for the same property makes absolutely no sense to me, therefore my brain must have TLDRed it :slight_smile: