Calculate discount, tax, and final price with small functions.
You are calculating the final price for a product after discount and tax. The discount is applied first, and tax is calculated on the discounted price.
Write these functions:
calculateDiscount(price, discountPercent) should return the discount amount.
calculateTax(priceAfterDiscount, taxPercent) should return the tax amount.
calculateFinalPrice(price, discountPercent, taxPercent) should subtract the discount, add tax, and return the final price.
createPriceSummary(price, discountPercent, taxPercent) should return an object with price, discount, tax, and finalPrice.
Sample checks:
Expected output:
Do not hardcode the example values. The functions should work for other prices and percentages too.
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.