Command Palette

Search for a command to run...

Hectal
Phase 2: Functions
TypeScript · Exercise 1 of 6Next
Beginner

Type a Function

clamp keeps a number between a lowest and a highest value. Strict mode complains because its parameters have no types.

Annotate all three parameters and the return type so it type-checks and prints 10 and 0. A call with text must be rejected.

What Check tests

  1. Your code has no type errors
  2. clamp("5", 0, 10) is rejected by TypeScript
  3. The console prints 10 and 0
  4. The return type is written

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.