Im trying to do concat/push if a condition is true but it’s returning after first insertion!! Btw, while using outside of “if-conditional” (e.g. console.log it’s showing all right values!!)
Your code so far
function checkCashRegister(price, cash, cid) {
let currencyUnits = {
PENNY: .01,
NICKEL: .05,
DIME: .1,
QUARTER: .25,
ONE: 1,
FIVE: 5,
TEN: 10,
TWENTY: 20,
"ONE HUNDRED": 100
};
billsChange = cash - price;
console.log(billsChange);
let availableUnits = {};
cid.forEach((item,idx)=>{
let key = item[0];
availableUnits[key] = item[1];
});
// return availableUnits;
for(let bills in currencyUnits) {
console.log(billsChange, billsChange > currencyUnits[bills]); // this shows all valid checks from list
let temp = [];
// for these conditionals it's not!!!!
// billsChange > currencyUnits[bills] ? temp = temp.concat(bills) : undefined
// if(billsChange > currencyUnits[bills]) temp.push(bills);
// if(billsChange > currencyUnits[bills]) temp = temp.concat(bills);
return temp;
}
}
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]]);
Can anyone please help me understand why it’s happening!!
Thanks y’all in advance!!
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0
.
Challenge: Cash Register
Link to the challenge: