Tell us what’s happening:
I was able to pass the first 2 tests but cannot make logic for the other ones. Need help.
Your code so far
function checkCashRegister(price, cash, cid) {
// Here is your change, ma'am.
var sum = [];
var temp = [];
var real = [["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
var dollars = [];
for (var x = 0; x < cid.length; x++) {
dollars.push([cid[x][0], cid[x][1] * real[x][1]]);
}
console.log(dollars);
var change = cash - price;
console.log(change);
for (var i = real.length-1; i >= 0; i--) {
console.log(real[i][1]);
while (real[i][1] < change) {
real[i][1] += real[i][1];
if (real[i][1] == change) {
sum.push(real[i]);
}
}
}
return {"status" : "OPEN", "change" : sum};
}
// 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.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register