Let's listen.
We are going to be adding in the gaming and functionality.
So right now, when we hit start, we see the button changes.
So the inter text changes as well as we get an output and then we're expecting a done to be clicked.
And this is what completes the calculation and all of the functionality.
So we're going to check to see if this inner text is equal to done and if it is that we know we need
to run our completion script and this is to complete the game.
So the first thing we're going to do it is we're going to do a complete opposite here.
So we're going to change this to true so the player can no longer type.
We're going to update the button so the entire text of the button changed that back to start so we can
start the game once again.
And this actually needs to be an else.
If so, we need to make sure that where else if if it's done, so start we type and we hit done and
it goes back to start, we can type again.
Done and we can't type anymore.
So now we need to run the game, end or end play function.
So let's go ahead and create that function and play.
And we need to do quite a bit of the same thing here that we have within the play game where we're getting
the current date to get the timestamp.
We're going to set the end time so that we have a completion time.
So end time equals date get time, so we get the same value.
So we have a start time globally and an end time globally.
So globally just means that these variables are sitting on the main part of the script so that we have
access to them.
And the way that variables work in JavaScript is that you can access the ones on the parent level,
but you can't access the ones within the child.
So that's where the scope variable scope is.
Let's calculate out the total time.
So creating a new variable for total time.
And this is where we can take that and subtracting out the start time and dividing by 1000.
And this is going to give us the total time that was played.
And remember that this is in milliseconds the end time and start time while we divide it by a thousand.
That's going to give us the number of seconds played and we can output that now.
And this is how many seconds we played the game.
So now we start one, two, three and done so it gave us roughly around three point seven, four, three
seconds of time played.
We also want to get the current input value here, so let's get that.
And that can just be a string, getting the player text, play, text and whatever value is associated
with there.
So that's going to get the content from there.
We can look at the number of words, and this is where we need to count the number of words, so show
you how to do that in the upcoming lessons, we need to count how many words count words.
So we need the number of words and then we can multiply and divide it by the total time words and then
we can output that final message to players.
So let's go ahead and do that in the upcoming lesson.
So right now, just build out that end, play function, update on the button to see if the button says
done.
And if it does, then we change it back to start.
We disable the text area and we run the function and play.
And then within here we create the end time and then we calculate out the total time.
And then we've got a few more things to do before we can wrap up this application.