1.A typed price function
BeginnerWrite total(price: number, quantity: number, discountPercent = 0): number and print the total for 3 items at ₹250 with no discount, and with a 10% discount.
Show hint
The default value makes discountPercent optional and infers it as a number.
Show solution
function total(price: number, quantity: number, discountPercent = 0): number {
const subtotal = price * quantity;
return subtotal - (subtotal * discountPercent) / 100;
}
console.log(total(250, 3), total(250, 3, 10));750 675