calculateTotal

JSDoc-documented utility function with a live interactive demo.

Source Code

/**
 * Calculates the total price after applying a percentage discount.
 *
 * @param {number} price - The original price before discount.
 * @param {number} discountPercent - The discount as a percentage (0–100).
 * @return {number} The final price after the discount has been applied.
 *
 * @example
 * // 20 % off a $50 item → $40
 * calculateTotal(50, 20); // returns 40
 */
function calculateTotal(price, discountPercent) {
  return price * (1 - discountPercent / 100);
}

Live Demo

Calculated Total
$40.00