Tell us what’s happening:
Why is it not logging my second console.log statement to the fcc console?
I am stuck here so how can I make this happen:
// you need to loop through the tendervalues from highest denomination to lowest denomination
// if the i'th denomination can be used to make change, use it to make change
// continue to use that denomination until either you run out of that denomination or you exceed the amount of change you need to give
// for (let i=0; i<tenderArray.length; i++){
// if (change<tenderArray[i]){
// cidArray[i]=cidArray[i]-tenderArray[i];
// }
// }
Your code so far
The work I did is unorganized, Not sure what pieces I should keep and what I should throw.
const tenderValues=
[["PENNY", 0.01 ],
["NICKEL", 0.05 ],
["DIME", 0.1],
["QUARTER", 0.25 ],
["ONE", 1],
["FIVE", 5],
["TEN", 10],
["TWENTY", 20],
["ONE HUNDRED", 100]]
function checkCashRegister(price, cash, cid) {
let change=price-cash;
let totalIndrawer=0;
for (let i=0; i<cid.length; i++){
totalIndrawer+=cid[i][1]
}
totalIndrawer= totalIndrawer.toFixed(2)
//console.log(totalIndrawer)
// let TenderName=[];
// let changeValue=[TenderName, sum];
let sum;
// const objReturn= { status:"" , change: changeValue };
let tenderArray=[];
for (let i=0; i<tenderValues.length; i++){
tenderArray.push(tenderValues[i][1]);
}
tenderArray=tenderArray.reverse()
console.log('this is tenderArray: '+tenderArray);
// you need to loop through the tendervalues from highest denomination to lowest denomination
// if the i'th denomination can be used to make change, use it to make change
// continue to use that denomination until either you run out of that denomination or you exceed the amount of change you need to give
// for (let i=0; i<tenderArray.length; i++){
// if (change<tenderArray[i]){
// cidArray[i]=cidArray[i]-tenderArray[i];
// }
// }
cidArray=[];
for (let i=0; i<cid.length; i++){
cidArray.push(cid[i][1])
}
cidArray=cidArray.reverse();
console.log('this is cidArray: '+cidArray);
}
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.86 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register