Is this a bug or am I doing soming wrong (maths isn't working)


#1


I have no idea what is going on. I have entered in the values that it has told me to but the math is not working for some reason. When I use a calculator to add up the values I get 16.93 but for some reason this code is printing out Your bill is 18.28? Plz help (also I have double and triple checked that my values are correct)

Error Message:
Oops, try again. Did you remember to add cases for magazine and chocolate? Are all your prices accurate?


var cashRegister = {
    total: 0,
//insert the add method here    
    add: function (itemCost){
        this.total+= itemCost;
    },
    
    scan: function (item) {
        switch (item) { 
        case "eggs": 
            this.add(0.98); 
            break;
        
        case "milk": 
            this.add(1.23); 
            break;
        case "magazine":
            this.add(4.99);
        case "chocolate":
            this.add(0.45);
        }
        return true;
    }
};

//Scan 2 eggs and 3 magazines
cashRegister.scan("magazine")
cashRegister.scan("magazine")
cashRegister.scan("magazine")
cashRegister.scan("eggs")
cashRegister.scan("eggs")
//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

never mind I figured it out forgot to add the break


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.