Summarize cart totals from arrays of item objects.
A cart contains items with a price and quantity. Build a summary that calculates subtotal, discount, tax, and final total.
Write these functions:
calculateSubtotal(items) should add price * quantity for every item.
calculateDiscount(subtotal, discountPercent) should return the discount amount.
calculateTax(amountAfterDiscount, taxPercent) should return the tax amount after the discount.
createCartSummary(items, discountPercent, taxPercent) should return an object with subtotal, discount, tax, and total.
Sample checks:
Expected output:
The subtotal must include every item and multiply each item's price by its quantity.
Join the Community
roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.
Roadmaps Best Practices Guides Videos FAQs YouTube
roadmap.sh by @kamrify @kamrify
Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.
Login or Signup
You must be logged in to perform this action.