var cashRegister = {
total:0,
add: function(itemCost){
total += this.itemCost;
},
scan: function(item) {
switch (item) {
case "eggs":
this.add(0.98);
break;
case "magazine":
this.add(4.99);
break;
}
return true;
}
};
cashRegister.scan("eggs");
cashRegister.scan("magazines");
console.log('Your bill is '+cashRegister.total);
the output show NAN, and total is undefined. I tried cashRegister.total and this.total in the add method, no luck. What's wrong with the code above?