TypeScript · Exercise 1 of 6Next
Beginner
Read a port from the environment
Environment variables are text or missing. Write readPort(env: Env): number that reads env["PORT"], throws an Error if it is missing, throws if it is not a whole number, and otherwise returns the number.
The type Env and an env object are given. The program must print port: 3000.
What Check tests
- Your code has no type errors
- The program prints port: 3000
- readPort returns a number
- The result is a number, not a string
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.