JSDoc-documented function with a live interactive demo.
/**
* 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); // => 40
*/
function calculateTotal(price, discountPercent) {
return price * (1 - discountPercent / 100);
}