Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 5, 2016 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/398b5c6c721475706f4bb08f28ceeae7 to your computer and use it in GitHub Desktop.
Save codecademydev/398b5c6c721475706f4bb08f28ceeae7 to your computer and use it in GitHub Desktop.
Codecademy export
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("magazine",4);
cashRegister.scan("milk",4);
cashRegister.scan("chocolate",4);
//Show the total bill
console.log('Your bill is '+cashRegister.total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment