-
-
Save sethschori/4b267cf25d93a5d719e3d7a163886f1c to your computer and use it in GitHub Desktop.
https://repl.it/CQGL/89 created by sethopia
This file contains 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
//Complete sumCart so that it will take the cart array and return the total cost for all | |
// the line items in the cart. | |
var cart = [ | |
["tofu", {"quantity" : 3,"price" : 4.5} ], | |
["sriracha", {"quantity" : 1,"price" : 5} ], | |
["toilet paper", {"quantity" : 12,"price" : 1.75} ], | |
["Drano", {"quantity" : 1,"price" : 13} ], | |
["orichette", {"quantity" : 2,"price" : 7.5} ], | |
["hummus", {"quantity" : 2,"price" : 5.99} ], | |
["bison meat", {"quantity" : 3,"price" : 20.99} ], | |
["vegan bison meat", {"quantity" : 3,"price" : 24.99} ] | |
]; | |
function sumCart(cart) { | |
var sum = 0; | |
for (var i = 0; i < cart.length; i++) { | |
var itemObj = cart[i][1] | |
sum += itemObj.quantity * itemObj.price; | |
} | |
return sum; | |
} | |
console.log(sumCart(cart)); |
This file contains 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
Native Browser JavaScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment