Skip to content

Instantly share code, notes, and snippets.

@cod3smith
Created December 7, 2020 09:45
Show Gist options
  • Save cod3smith/82f6a55be3fe81bca643791880d95666 to your computer and use it in GitHub Desktop.
Save cod3smith/82f6a55be3fe81bca643791880d95666 to your computer and use it in GitHub Desktop.
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