Can anybody explain this problem?

Tell us what’s happening:

Your code so far


function checkCashRegister(price, cash, cid) {
var change;
// Here is your change, ma'am.
return change;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

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/79.0.3945.117 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

What specifically do you need explained?

well, with this code, you create an undefined variable (change) and then you return that value undefined. That would be a problem.

what we need to return in change array.

i haven’t written any code, i was just understanding the problem

could you please tell what of the challenge description is unclear?

The return values are pretty clearly explained in the sidebar. In every case, we want to return an object with two properties:

{
  status: 'some-status-message here',
  change: [/* an array of change being returned */
}
  • If the change in the drawer currently is not enough to cover the change due, OR if we can’t make exact change for the given amount (lacking enough pennies, say), we need to return an “INSUFFICIENT FUNDS” message and no change at all (that is, an empty change array.
  • If the change in the drawer is exactly what is needed to cover the change due, we return a “CLOSED” message with the exact copy of cid as the change array.
  • Otherwise, we can make the change for this transaction, so our message returned should be “OPEN” and the change should be an array of the exact change used to create the proper amount.

There is some funky logic in here, and there is some math. You are exactly right to pre-plan, and to ask questions. I often find, with a complex challenge like this, that I need to break it down in terms I understand, and map out the exact steps for each possible branch.