JavaScript Cash Register

Requirements

Implementation

checkCashRegister(price, cash, cid) calculates the required change for a purchase. price is the purchase price, cash is the cash payment amount, cid is the "cash-in-drawer" array. Returns an object containing "status" string and "change" array.

Example Usage

Use the browser console to interact with the function (Ctrl + Shift + I, then select the "Console" tab):

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

// Returns:
// { status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]] }