Created
December 7, 2020 09:45
-
-
Save cod3smith/82f6a55be3fe81bca643791880d95666 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
const calculateTotal = () => { | |
// Assume this your cart. | |
let cartArr = [ | |
{ | |
'price': 1000, | |
'quantity': 12 | |
}, | |
{ | |
'price': 2000, | |
'quantity': 22 | |
}, | |
{ | |
'price': 3000, | |
'quantity': 32 | |
} | |
]; | |
let grandTotal = 0; | |
cartArr.forEach(function (cartItem) { | |
let productTotal = cartItem.price * cartItem.quantity; | |
grandTotal += productTotal; | |
console.log(productTotal); | |
console.log(grandTotal); | |
}); | |
} | |
console.log(calculateTotal()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment