Please help me understand!

Tell us what’s happening:
I have read over and over again since few days, but I don’t still understand what I’m suppose to do, not to mention writing any code.

Please help me understand the change key , from:

=> The checkCashRegister() function should always return an object with a status key and a change key.

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

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

Thanks in advance!

Your code so far

function checkCashRegister(price, cash, cid) {
var change;
return change;

checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

An object can hold one to several key-value pairs. This stack overflow post helps illustrate this concept.

For this problem, it’s asking for a returned object with a status key (and associated value) and a change key (and associated value). It should look something like this:

return {
  status: [status value],
  change: [change value]

The actual values for each key are demonstrated in what you also posted, with the “INSUFFICIENT_FUNDS” and values associated with those keys. With the change key, you will want to run the tests and see what the expected value is for the tests you are failing to help give you an idea of what to input.

I hope this helps!

Maybe I am not clear enough, I am sorry.
It is the change key that I am confused about - I don’t know what it means.

I should know to do if I understand the challenge.

Let me ask this way:
why was {status: "OPEN", change: **[["QUARTER", 0.5**]**]} returned from the first user story, I would say

If something costs $0.50 and you give the seller a $1 bill, then the seller gives you back $0.5 cents. The $0.5 cents is the “change”. If the seller has two quarters (worth $0.25 each) then they will give you two quarters. In this case your “change” would be “$0.5 in quarters”.

1 Like

No worries.

The first (and second) user story has checkCashRegister(19.5, 20, [lots of values]). The cost of the item is 19.5, or $19.50. The customer gives you 20, or $20.00, of cash. The difference between the two is $0.50, or 0.5. Since there is at least $0.50 worth of quarters in the [lots of values] cash register, you are able to return that amount worth of quarters to the customer in change, or [["QUARTER", 0.5]]. Technically, you could return that amount in dimes, nickels, or pennies if you have enough, but the most optimal return method is 2 quarters, or $0.50 at $0.25 each.

This problem is pretty tough, and I hope that helps to answer your question. I would also recommend looking at the hint for the challenge either, as it helps to guide your thinking on solving this problem:

Thanks a bunch @ArielLeslie @darren-stoll!!