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
- Your code has no type errors
clamp("5", 0, 10)is rejected by TypeScript- The console prints
10and0 - 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.
Press Run to see the page.
Console
Nothing printed yet.