Last active
January 28, 2018 06:58
-
-
Save daniellealexis/c0ab9906c720dab0aca83a43da0f8520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var coffeeShoppe = {}; | |
| coffeeShoppe.coffee = 5.25; | |
| coffeeShoppe.latte = 4.25; | |
| coffeeShoppe.cheesecake = 4.00; | |
| /** | |
| * Get the price of the passed-in product name | |
| * @param {string} productName | |
| * @return {number|undefined} | |
| */ | |
| coffeeShoppe.getPrice = function(productName){ | |
| return this[productName]; | |
| } | |
| /** | |
| * Get the total price of a list of products | |
| * @param {string[]} productList | |
| * @return {number} | |
| */ | |
| coffeeShoppe.calculateTotalPrice = function(productList) { | |
| let total = 0; | |
| const productCount = productList.length; | |
| for (var i = 0; i < productCount; i++) { | |
| var price= this.getPrice(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