0 of 5 problems solved0%
2 of 5

Number Inference in Functions

Previously, you saw that TypeScript can figure out a variable's type just from its initial value — this is called type inference.

The same works for functions. If a function returns a number, TypeScript will know its return type is number without you writing it. But if you don't return anything, its type will be void.

Your Task

  1. Complete the function calculateAppleCost that takes the number of apples as a parameter and returns the total cost, given each apple costs 5.

  2. Hover over total in the editor to see its type change from void (before you implement the function) to number (after you return a value).

Example output if you pass 3:

15

Hint

Multiply the number of apples by 5 to get the cost.