Extra study: Build a Cash Register
Every time I give this module a visit it ends up drawing me in. Tonight it is this,
price: function(item) {
switch (item){
case "eggs": return 0.98;
case "milk": return 1.23;
case "magazine": return 4.99;
case "chocolate": return 0.45;
default: return false;
}
},
scan: function(item, quantity) {
var price = this.price(item);
if (price) {
this.add(quantity * price);
return true;
}
return false;
},
This reduces the price list to a case-value pair, setting the stage for a plain object approach.