calculateTotalJSDoc-documented function with a live interactive demo.
/**
* Calculates the total price after applying a percentage discount.
*
* @param {number} price - The original price of the item.
* @param {number} discountPercent - The discount to apply, expressed as a
* percentage (e.g. 20 for 20%).
* @return {number} The final price after the discount has been applied.
*
* @example
* // A $100 item with a 20% discount costs $80.
* calculateTotal(100, 20); // => 80
*/
function calculateTotal(price, discountPercent) {
return price * (1 - discountPercent / 100);
}