Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created November 2, 2014 01:48
Show Gist options
  • Save JacobHsu/efd9186e3fee55afd940 to your computer and use it in GitHub Desktop.
Save JacobHsu/efd9186e3fee55afd940 to your computer and use it in GitHub Desktop.
#JS Building a Cash Register
var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
}
};
//call the add method for our items
var items = [0.98, 1.23, 4.99, 0.45];
for(i=0;i<items.length;i++){
cashRegister.add(items[i]);
}
//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