Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 14, 2016 07:12
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/c0de48107d1a4687621e8638de98c355 to your computer and use it in GitHub Desktop.
Save codecademydev/c0de48107d1a4687621e8638de98c355 to your computer and use it in GitHub Desktop.
Codecademy export
var cashRegister = {
total: 0,
//insert the add method here
add: function(itemCost){
this.total += itemCost;
}
scan: function (item) {
switch (item) {
case "eggs":
this.add(0.98);
break;
case "milk":
this.add(1.23);
break;
//Add other 2 items here
case "magazine":
this.add(4.99);
break;
case "chocolate":
this.add(0.45);
break;
}
return true;
}
};
//Scan 2 eggs and 3 magazines
cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
//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