Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 7, 2016 08:04
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/54abfe0f643944b0a9769e257ef04256 to your computer and use it in GitHub Desktop.
Save codecademydev/54abfe0f643944b0a9769e257ef04256 to your computer and use it in GitHub Desktop.
Codecademy export
var cashRegister = {
total:0,
lastTransactionAmount:0,
//Dont forget to add your property
add: function(itemCost) {
this.lastTransactionAmount = itemCost;
this.total += this.lastTransactionAmount;
},
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;
}
return true;
},
//Add the voidLastTransaction Method here
voidLastTransaction: function () {
this.total -= this.lastTransactionAmount;
this.lastTransactionAmount = 0;
}
};
cashRegister.scan('eggs',3);
cashRegister.scan('milk',3);
cashRegister.scan('magazine',3);
cashRegister.scan('chocolate',3);
//Void the last transaction and then add 3 instead
cashRegister.voidLastTransaction();
//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