If Conditionals in an Object Iteration doesn't passing through After First TRUE Case!

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;
            let availableUnits = {};
                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:

You have a return inside your loop. Remember that a return statement exits the function. No further code will be executed. Because your loop has a return only the first value will ever be checked.

1 Like

Ohh, shoot, I didn’t realize that at all!! Thank you for pointing that out, much appreciated.

I’m glad I could help. Happy coding!

1 Like