Calculate discount, tax, and final price with small functions.
Start building, submit solution and get feedback from the community.
2Submit Solution
5 upvotes10 upvotes
Price Calculator
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.