Shopping cart total
Use reduce() to count the items in a cart and add up what they cost.
intermediateJavaScript
The task
An online shop keeps the cart as an array of objects. Calculate two things with reduce():
- How many items are in the cart (add up every
qty). - The total price:
price × qtyfor every item, added together.
Print them like the expected output below, with the total rounded to 2 decimals (toFixed(2)).
Your output should be:
Items: 15 Total: $36.49