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
index.ts
and create these exported functions with typed parameters and explicit return types:
  1. 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
  2. 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"
  3. 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, applyDiscount

Completion criteria

The examples above must all pass. Prefer keeping return types explicit even though this step focuses on parameter types.

Please set the playground first

Loading "Function Parameters"
Loading "Function Parameters"
Login to get access to the exclusive discord channel.
Loading Discord Posts