I have to scan it more than once, help


#1

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("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("chocolate",4);

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


#2

you have done your calculation in wrong place for example
case "eggs": this.add(0.98) * quantity; break;
should be
case "eggs": this.add(0.98 * quantity); break; // calculation inside the brackets.


#3

Full code:

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

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

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