Intermediate
Run a function when Enter is pressed
Write onEnter(input: HTMLInputElement, run: (text: string) => void): void. When the user presses the Enter key in the input, call run with the input's current text. Other keys do nothing.
The page already calls your function for the input #box and logs got <text> from the callback.
Let TypeScript give the event its type. Do not annotate the event parameter.
What Check tests
- Your code has no type errors
- Enter calls the callback with the text
- Other keys do nothing
- A callback taking a number is rejected
- No annotation on the event
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.
Your page
Press Run to see the page.
Console
Nothing logged yet.