Skip to content

Instantly share code, notes, and snippets.

@daniellealexis
Last active January 28, 2018 06:57
Show Gist options
  • Select an option

  • Save daniellealexis/586719b9b30b5e7256f3ab7875bb58f8 to your computer and use it in GitHub Desktop.

Select an option

Save daniellealexis/586719b9b30b5e7256f3ab7875bb58f8 to your computer and use it in GitHub Desktop.
var coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
coffeeShoppe.getProductPrice = function(productName){
return this[productName];
}
coffeeShoppe.calculateTotalPrice = function(productList) {
let total = 0;
const productCount = productList.length;
for (var i = 0; i < productCount; i++) {
var price= this.getProductPrice(productList[i]);
if (typeof price == 'number') {
total += price;
}
}
return total;;
}
coffeeShoppe.calculateTotalPrice(['bagel', 'coffee','latte']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment