Function Parameters
Parameters
π¨βπΌ We need utility functions for our e-commerce platform. Let's focus on
functions that accept clear inputs and return the right type.
π¨ Open
and create these exported functions with
typed parameters and explicit return types:
-
calculateTax(amount: number, rate: number): numberβ returns the tax amount for the given amount and rate. Examples:calculateTax(100, 0.08)β8;calculateTax(50, 0.1)β5 -
formatPrice(cents: number): stringβ converts whole cents into a dollar string with a$prefix and exactly two decimal places. Examples:formatPrice(1999)β"$19.99";formatPrice(100)β"$1.00";formatPrice(50)β"$0.50" -
applyDiscount(price: number, discountPercent: number): numberβ returns the price after a percentage discount is applied. Examples:applyDiscount(100, 20)β80;applyDiscount(50, 10)β45;applyDiscount(200, 25)β150
Required exports
calculateTax, formatPrice, applyDiscountCompletion criteria
The examples above must all pass. Prefer keeping return types explicit even
though this step focuses on parameter types.