calculateTotal Function Documentation & Live Demo

Function Documentation

function calculateTotal(price, discountPercent) {
        * @param price - The original price before discount (number)
        * @param discountPercent - The discount percentage to apply (number)
        * @return The final price after applying the discount (number)
        * @example
        * Calculate total for a $100 item with 20% discount:
        * const result = calculateTotal(100, 20); // returns 80
        * Calculate total for a $50 item with 15% discount:
        * const result = calculateTotal(50, 15); // returns 42.5
        * return price * (1 - discountPercent / 100);
                }
            

Live Interactive Demo

Enter values to see the calculated total