1
00:00:00,420 --> 00:00:04,940
This is going to be a quick bonus lesson, how to make the scheme even better.

2
00:00:05,100 --> 00:00:11,610
So currently we have a game, we hit start, we can type some content and we see we type 31 words per

3
00:00:11,610 --> 00:00:14,310
minute and we see there were some errors with the wording.

4
00:00:14,520 --> 00:00:19,800
And what I want to do in this lesson is actually count how many words were incorrect.

5
00:00:20,130 --> 00:00:24,030
And the way that I'm going to do that is I'm going to take this value.

6
00:00:24,030 --> 00:00:27,720
I'm going to take the value from here, both of those string values.

7
00:00:27,870 --> 00:00:33,510
I'm going to use that split from the string object, turn them into arrays and then loop through the

8
00:00:33,510 --> 00:00:34,680
contents of the array.

9
00:00:34,710 --> 00:00:36,960
Do comparison word by word.

10
00:00:37,210 --> 00:00:45,090
So let's set up that function, string one and string two, and we're going to do a comparison of both

11
00:00:45,090 --> 00:00:45,380
of them.

12
00:00:46,470 --> 00:00:52,620
So let's create that first split and we're going to split it by spaces.

13
00:00:52,980 --> 00:01:00,510
Let words to equal string two split by space.

14
00:01:00,900 --> 00:01:03,690
And now we're going to loop through one of the strings.

15
00:01:03,990 --> 00:01:05,190
Let's just take words.

16
00:01:05,190 --> 00:01:10,830
One, we're going to loop through each one of those and we can use the for each or we could use any

17
00:01:10,830 --> 00:01:15,000
type of loop that we want that's going to iterate through each one of the items.

18
00:01:15,710 --> 00:01:22,350
Then within here function, we've got our item and for now we can console lock out the item and we're

19
00:01:22,350 --> 00:01:30,270
going to launch the function, compare words so we know we've got message, text one and we've got our

20
00:01:30,270 --> 00:01:32,060
string that we're going to pass in there.

21
00:01:32,610 --> 00:01:33,550
So let's see what happens.

22
00:01:33,840 --> 00:01:37,200
So refresh hit start test done.

23
00:01:37,410 --> 00:01:42,150
And we can see that we broke up all of the words here within our string.

24
00:01:42,510 --> 00:01:44,130
So source code is included.

25
00:01:44,130 --> 00:01:49,200
You can your own version of this challenge so we can try that again.

26
00:01:49,350 --> 00:01:52,950
And we can see once again we get all of the words out there.

27
00:01:53,760 --> 00:01:59,760
So now that we're looping through them, we need to compare each one of those and we need to also get

28
00:01:59,760 --> 00:02:01,050
an index value here.

29
00:02:01,050 --> 00:02:07,260
So let's output the index and refresh and we can get the index using for each as well.

30
00:02:07,530 --> 00:02:13,290
And the index is what we can use for the other array where we've got words to.

31
00:02:13,860 --> 00:02:15,180
So let's refresh.

32
00:02:15,180 --> 00:02:19,530
We see that those are coming up undefined because we're not actually typing any of those words.

33
00:02:20,190 --> 00:02:25,410
So even if I type a few of the first ones, we can see that the first ones do match and then the rest

34
00:02:25,410 --> 00:02:26,120
don't match.

35
00:02:26,430 --> 00:02:28,050
So that's exactly what we want to do.

36
00:02:28,230 --> 00:02:32,700
So we need to do a comparison here to check to see if they are correct.

37
00:02:32,820 --> 00:02:35,670
And if they are correct, then we're going to continue.

38
00:02:35,820 --> 00:02:40,890
And if they're not correct, then we're going to return back that they weren't that they were incorrect.

39
00:02:41,190 --> 00:02:47,580
So having our condition, we're going to check to see if item is equal to words to index.

40
00:02:48,000 --> 00:02:53,160
And if it is, then we know that we've got the count plus one.

41
00:02:53,880 --> 00:02:55,590
Let's set up count here.

42
00:02:55,950 --> 00:03:02,490
So now count will increment every time they are correct and nothing will happen every time they are

43
00:03:02,490 --> 00:03:02,970
wrong.

44
00:03:03,480 --> 00:03:08,160
And now we can console log out and that will show us how many words were correct.

45
00:03:08,370 --> 00:03:09,840
So once again, we'll do start.

46
00:03:10,230 --> 00:03:10,860
Hope you.

47
00:03:11,250 --> 00:03:12,420
So we should have two.

48
00:03:12,450 --> 00:03:12,960
Correct.

49
00:03:12,960 --> 00:03:13,530
Which we do.

50
00:03:13,800 --> 00:03:15,480
And then we can do out of.

51
00:03:16,260 --> 00:03:22,020
And this can actually count how many words we had within our words.

52
00:03:22,050 --> 00:03:23,820
One start again.

53
00:03:24,070 --> 00:03:25,060
We'll try that again.

54
00:03:25,080 --> 00:03:26,550
So hope you are having fun.

55
00:03:26,820 --> 00:03:29,900
We see that to correct out of thirteen.

56
00:03:30,630 --> 00:03:32,580
So this is what we can return back.

57
00:03:32,580 --> 00:03:34,770
So let's return that back out.

58
00:03:35,340 --> 00:03:42,480
And instead of outputting that, we're going to simply add to the final message, whatever gets returned

59
00:03:42,480 --> 00:03:44,340
back from this function.

60
00:03:44,940 --> 00:03:49,820
And we can get rid of this part and we can get rid of that part and just clean that up one more time.

61
00:03:50,520 --> 00:03:54,630
So now we're actually going to get a count of how many words we got.

62
00:03:54,630 --> 00:03:55,110
Correct.

63
00:03:55,380 --> 00:03:57,480
So we got to correct out of nine.

64
00:03:57,750 --> 00:04:01,020
And we can add in words as well there within that string.

65
00:04:01,800 --> 00:04:03,090
So start one more time.

66
00:04:03,540 --> 00:04:04,500
So see how many we got?

67
00:04:04,500 --> 00:04:06,090
We got five out of thirteen.

68
00:04:06,090 --> 00:04:06,570
Correct.

69
00:04:07,050 --> 00:04:11,730
So this gives us a little bit more of an accurate response instead of just saying that we were right

70
00:04:11,730 --> 00:04:12,330
or wrong.

71
00:04:12,480 --> 00:04:17,010
So when I do start and if I just hit done, I got zero correct out of nine words.

72
00:04:17,190 --> 00:04:23,250
And as well you can add additional customizations to this to improve this application as well.
