Cash Register 3.3 help needed


#1
var cashRegister = {
total: 0,
//insert the add method here

add: function(itemCost){
this.total += itemCost;
}, 

scan: function (item, qty) {
    switch (item) { 
    case "eggs": 
        this.add(0.98 * qty); 
        break;

    case "milk": 
        this.add(1.23 * qty); 
        break;

    case "magazine":
        this.add(4.99 * qty);
        break;

    case "chocolate":
        this.add(0.45 * qty);
        break;
    }
    return true;
}
};

cashRegister.scan("eggs",2);
cashRegister.scan("magazine",3);

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

Output is: Your bill is 16.93

but getting error message:
**"Oops, try again. **
Did you remember to add cases for magazine and chocolate? Are all your prices accurate?"
and task doesn't passes.

What can be wrong?


#2

@andrewzot,

The scans must also be done in the right order or a Codeacademy error will occur.
// scan each item 4 times
cashRegister.scan("eggs",4);
cashRegister.scan("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("chocolate",4);


#3

thanks.
works now.
Updated to canonical view

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);
        break;

    case "chocolate":
        this.add(0.45);
        break;
    }
    return true;
}
};

cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
console.log('Your bill is '+ cashRegister.total);