Tell us what’s happening:
Hi all, I’m in need of some guidance with this final problem for the JavaScript section: the cash register problem. I have been struggling through this section, but pushing myself more than ever. I feel rather frustrated with this problem, because I can’t even begin to imagine where to start. I’m determined to not seek out others answers until I discover my own resolution for this problem, but not sure how to even brainstorm what needs to be done, on paper. Below I have some starter variables, and an array of objects that holds the value of each dollar/coin amount, like FCC suggests, and a tiny function to measure the sum of the “cash in drawer”, besides that I don’t know where to start. I’ve brainstormed many ways of looping through the cid argument, and the currency variable i created, but can’t determine how to get the values to make up the “change due”. I’ve been staring at this problem for almost a week now and can’t wrap my head behind the problem. Any direction is really appreciated. Thank you.
Your code so far
function checkCashRegister(price, cash, cid) {
let currency = [
{ name : 'ONE HUNDRED', val : 100.00},
{ name : 'TWENTY', val : 20.00},
{ name : 'TEN', val : 10.00},
{ name : 'FIVE', val : 5.00},
{ name : 'ONE', val : 1.00},
{ name : 'QUARTER', val : 0.25},
{ name : 'DIME', val : 0.10},
{ name : 'NICKEL', val : 0.05},
{ name : 'PENNY', val : 0.01}
];
let changeFromTransaction = cash - price;
let cashInDrawer = 0;
let changeDue = 0;
for (let i = 0; i < cid.length; i++){
cashInDrawer += cid[i][1];
}
console.log(cashInDrawer);
console.log(changeFromTransaction);
}
console.log(JSON.stringify(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/73.0.3683.103 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register