Tell us what’s happening:
I am going about the solution slightly differently than the “Get a Hint” solution.
I’ve had challenges with more complex topics, such as variable arrays, and Loops. So, I wanted to just glance at how the “Get a Hint” solution was solving, just to get an idea.
I am having a bit of a problem understanding what goes after the dot in the following:
cid.reduce(function(acc, curr)
register.total === change
register[curr.name] > 0 && change >= curr.val
output.status = ‘CLOSED’ ==> this one seems to make sense, as I see the variable declared: var output = { status: null, change: [] };
Can you maybe refer me to a lesson(s) that talks about .reduce, .total, curr.name? Is .reduce a math operator?
I am thinking of using a % mod operator to count the bills and coins. I am having a hard time understanding how the “Get a Hint” solution counts out these bills and coins. I feel a bit lost in the sea of dot.words and the many variables being used.
Thank you.
Your code so far
var price;
var cash;
var cid;
function checkCashRegister(price, cash, cid) {
var change;
var status;
change=cash-price; // cash paid to cashier minus price equals change to return to customer
var moneyLeftInDrawer=cid[1]-change; // moneyLeftInDrawer will determine the "status" (insuf funds, closed, open)
if (moneyLeftInDrawer<0){
return {status: "INSUFFICIENT_FUNDS", change: []};
} else if (moneyLeftInDrawer=0){
return {status:"CLOSED", change: []};
} else if (moneyLeftInDrawer>0){
return {status:"OPEN", change: []};
}
var PENNY, NICKEL, DIME, QUARTER, ONE, FIVE, TEN, TWENTY, ONE HUNDRED;
/*
--- work in progress below --- :)
return change (return in coins and bills); >>
if change coins and bills include >> PENNY, NICKEL, DIME, QUARTER, ONE, FIVE, TEN, TWENTY, ONE HUNDRED (ex. 2.05 == 2 ONE's, 1 NICKEL -- add "Dollar Bill(s)" after reporting bills;
BILLS:
0-4 >> return ONE "Dollar Bill(s)"
5 >> return FIVE
6-9 >> return 1 FIVE and subtract five to obtain number of ONE Dollar Bills to return
10 >> return TEN
suppose you have $121.72 to return change to customer.
use %100 will rtn 1; >> if %100 >0 store result in HUNDRED variable & then return HUNDRED + "Dollar Bill(s)";
then subtract HUNDRED*100 from change;
use %20 will rtn 1; >> if %20>0 store results in TWENTY variable & then return TWENTY + "Dollar Bill(s)";
usee %10 ... (continue above process)
use %5
use %1
use %0.25
use %0.10
use %0.05
use %0.01
note: change will become an object/var array of coins and bills.
e.g. obj or var change (){
HUNDRED: amount,
TWENTY: amount,
TEN: amount,
...
--- WORK IN PROGRESS ABOVE ---
*/
}
}
// 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 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register