#4. Everything seems to be in check but I can't find my error


#1



Hoping a second set of eyes can tell me what I'm missing. I get the output: Your bill is 30.600000000000005
But the error: Oops, try again. Did you scan four of each item?

Thanks in advance!


    var cashRegister = {
        total:0,
        add: function(itemCost){
            this.total += itemCost;
        },
        scan: function(item, quantity) {
            switch (item) {
            case "eggs": this.add(0.98 * quantity); 
            break;
            case "milk": this.add(1.23 * quantity); 
            break;
            case "magazine": this.add(4.99 * quantity); 
            break;
            case "chocolate": this.add(0.45 * quantity); 
            break;
            }
        }
    };

    // scan each item 4 times
    cashRegister.scan("eggs", 4);
    cashRegister.scan("magazine", 4);
    cashRegister.scan("milk", 4);
    cashRegister.scan("chocolate", 4);


    //Show the total bill
    console.log('Your bill is '+ cashRegister.total);


#2

@netninja33070
Try it with changed call-order
like

cashRegister.scan("eggs", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("chocolate", 4);

#3

Thanks! I ended up just clearing my cache and it let me through :slight_smile: