First you need to think about time past.
A common logical way to do this is as so:
1) User presses a key - set time of "now" to a variable lets say "start".
2) User stops typing - compare "now" to "start" to get time passed.
You can use something like this for time:
So how do we detect a user pressed a key:
Now for typing you can use something called an event listener.
keyup might be of interest to you here.
But every letter the user types will involve a keydown and keyup and a keypress. So to signify the "end" of the user typing his or her sentence you might want ot listen to a specific button on the keyboard - perhaps the enter key. Once that button is pressed then you compare the time elapsed as enter key would signify the end of the input.
So once you set up the listeners to listen for specific actions from the user - you will want that event listener to call a function that compares time elapsed using basic mathematics of your two time stamps, then print that time elapsed on screen.