1
00:00:00,240 --> 00:00:00,890
Let's listen.

2
00:00:00,930 --> 00:00:04,560
We are going to be adding in the gaming and functionality.

3
00:00:04,710 --> 00:00:08,480
So right now, when we hit start, we see the button changes.

4
00:00:08,490 --> 00:00:14,280
So the inter text changes as well as we get an output and then we're expecting a done to be clicked.

5
00:00:14,310 --> 00:00:19,040
And this is what completes the calculation and all of the functionality.

6
00:00:19,470 --> 00:00:28,200
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

7
00:00:28,200 --> 00:00:33,700
to run our completion script and this is to complete the game.

8
00:00:34,080 --> 00:00:37,700
So the first thing we're going to do it is we're going to do a complete opposite here.

9
00:00:38,040 --> 00:00:42,410
So we're going to change this to true so the player can no longer type.

10
00:00:43,590 --> 00:00:52,470
We're going to update the button so the entire text of the button changed that back to start so we can

11
00:00:52,470 --> 00:00:53,780
start the game once again.

12
00:00:54,240 --> 00:00:56,190
And this actually needs to be an else.

13
00:00:56,190 --> 00:01:03,000
If so, we need to make sure that where else if if it's done, so start we type and we hit done and

14
00:01:03,000 --> 00:01:05,520
it goes back to start, we can type again.

15
00:01:05,550 --> 00:01:07,780
Done and we can't type anymore.

16
00:01:08,130 --> 00:01:13,220
So now we need to run the game, end or end play function.

17
00:01:13,470 --> 00:01:16,470
So let's go ahead and create that function and play.

18
00:01:16,660 --> 00:01:22,110
And we need to do quite a bit of the same thing here that we have within the play game where we're getting

19
00:01:22,110 --> 00:01:24,390
the current date to get the timestamp.

20
00:01:24,630 --> 00:01:29,790
We're going to set the end time so that we have a completion time.

21
00:01:30,120 --> 00:01:36,750
So end time equals date get time, so we get the same value.

22
00:01:36,770 --> 00:01:40,200
So we have a start time globally and an end time globally.

23
00:01:40,380 --> 00:01:47,070
So globally just means that these variables are sitting on the main part of the script so that we have

24
00:01:47,070 --> 00:01:47,880
access to them.

25
00:01:48,090 --> 00:01:54,360
And the way that variables work in JavaScript is that you can access the ones on the parent level,

26
00:01:54,660 --> 00:01:57,180
but you can't access the ones within the child.

27
00:01:57,420 --> 00:02:00,300
So that's where the scope variable scope is.

28
00:02:00,450 --> 00:02:02,900
Let's calculate out the total time.

29
00:02:03,420 --> 00:02:06,140
So creating a new variable for total time.

30
00:02:06,960 --> 00:02:15,170
And this is where we can take that and subtracting out the start time and dividing by 1000.

31
00:02:15,660 --> 00:02:18,060
And this is going to give us the total time that was played.

32
00:02:18,390 --> 00:02:23,720
And remember that this is in milliseconds the end time and start time while we divide it by a thousand.

33
00:02:23,730 --> 00:02:28,130
That's going to give us the number of seconds played and we can output that now.

34
00:02:28,170 --> 00:02:30,630
And this is how many seconds we played the game.

35
00:02:31,170 --> 00:02:38,730
So now we start one, two, three and done so it gave us roughly around three point seven, four, three

36
00:02:38,730 --> 00:02:40,790
seconds of time played.

37
00:02:41,250 --> 00:02:47,100
We also want to get the current input value here, so let's get that.

38
00:02:47,100 --> 00:02:55,620
And that can just be a string, getting the player text, play, text and whatever value is associated

39
00:02:55,620 --> 00:02:56,130
with there.

40
00:02:56,310 --> 00:02:58,440
So that's going to get the content from there.

41
00:02:59,450 --> 00:03:05,240
We can look at the number of words, and this is where we need to count the number of words, so show

42
00:03:05,240 --> 00:03:10,790
you how to do that in the upcoming lessons, we need to count how many words count words.

43
00:03:10,790 --> 00:03:17,690
So we need the number of words and then we can multiply and divide it by the total time words and then

44
00:03:17,690 --> 00:03:21,450
we can output that final message to players.

45
00:03:21,470 --> 00:03:24,080
So let's go ahead and do that in the upcoming lesson.

46
00:03:24,500 --> 00:03:31,550
So right now, just build out that end, play function, update on the button to see if the button says

47
00:03:31,550 --> 00:03:31,910
done.

48
00:03:31,910 --> 00:03:35,270
And if it does, then we change it back to start.

49
00:03:35,480 --> 00:03:39,770
We disable the text area and we run the function and play.

50
00:03:39,890 --> 00:03:45,320
And then within here we create the end time and then we calculate out the total time.

51
00:03:45,470 --> 00:03:49,700
And then we've got a few more things to do before we can wrap up this application.
