calculateTotal Function

Documentation

/**
 * Calculates the total price after applying a percentage discount.
 *
 * @param {number} price - The original price of the item.
 * @param {number} discountPercent - The discount percentage to apply (0-100).
 * @returns {number} The final price after the discount is applied.
 * @example
 * // Calculate total for a $100 item with 20% discount
 * const total = calculateTotal(100, 20);
 * console.log(total); // Output: 80
 */
function calculateTotal(price, discountPercent) {
  return price * (1 - discountPercent / 100);
}

Live Demo

Total: $0.00