1
00:00:00,150 --> 00:00:05,250
This lesson, we're going to be putting the final touches on our accomplis, we come in as the player

2
00:00:05,250 --> 00:00:11,550
has to select either heads or tails, they select heads or tails, and then the computer randomly generates

3
00:00:11,550 --> 00:00:12,770
either heads or tails.

4
00:00:13,020 --> 00:00:17,940
If they selected correctly and got the same answer that the computer got, then they're going to get

5
00:00:17,940 --> 00:00:18,390
a point.

6
00:00:18,510 --> 00:00:23,940
If they got the wrong answer, if they made the wrong selection, then they are they are not going to

7
00:00:23,940 --> 00:00:26,040
get a point and the computer is going to get a point.

8
00:00:26,580 --> 00:00:32,850
So our logic is fairly straightforward in this game because we can use a conditional statement to check

9
00:00:32,850 --> 00:00:37,470
if the player's response is equal to the response of the computer.

10
00:00:37,590 --> 00:00:39,810
And if it is, then this is a win.

11
00:00:39,990 --> 00:00:46,500
And if it's not, then it's a loss and we can use an awful statement in order to handle all of that.

12
00:00:47,100 --> 00:00:53,610
Also, another thing that usually I like to do is to shorten some of the content here so we can have

13
00:00:53,610 --> 00:00:59,840
a player guess value and more meaningful variables as well.

14
00:01:00,970 --> 00:01:03,610
So add that in as the player gets.

15
00:01:04,850 --> 00:01:12,710
And we can also set one up for the computer guess as well, so that we have more of a meaningful variable

16
00:01:12,710 --> 00:01:15,200
name as to what these values are.

17
00:01:16,750 --> 00:01:24,010
So that's the player, guess that's the computer, guess now we can compare if the player guess is equal

18
00:01:24,010 --> 00:01:29,320
to the computer, guess then we have a win, otherwise we have a loss.

19
00:01:30,410 --> 00:01:36,810
Also, let's set up some scoring, and this is actually needs to be Aulet, because the value will change.

20
00:01:37,070 --> 00:01:42,260
So we've got our score creating an array because we've got two players here.

21
00:01:42,270 --> 00:01:44,620
We've got the computer and we've got the player.

22
00:01:44,810 --> 00:01:48,350
So one of them will be the first one and the other one will be the second.

23
00:01:48,860 --> 00:01:55,880
Now, going into here, we can take that value of score, take the first one and we'll increment it

24
00:01:55,880 --> 00:01:56,390
by one.

25
00:01:56,990 --> 00:02:03,080
And if it's a loss, then we're going to do the opposite and we're going to increment the score with

26
00:02:03,080 --> 00:02:03,990
index one.

27
00:02:04,700 --> 00:02:07,730
We will also output those score values.

28
00:02:09,320 --> 00:02:18,800
So using the message, we can add that in our HTML so we can set that into player and also setting up

29
00:02:18,800 --> 00:02:20,240
a default variable here.

30
00:02:20,240 --> 00:02:22,330
So default output.

31
00:02:23,210 --> 00:02:31,190
And then once we get that condition, we can set a value that player wins, otherwise the output will

32
00:02:31,190 --> 00:02:38,860
be equal to computer wins and now we can output that content into the inner message there.

33
00:02:39,170 --> 00:02:40,520
Let's add a new line.

34
00:02:40,730 --> 00:02:47,990
So line break there and we can have the score values so the player will have a value of whatever score

35
00:02:48,080 --> 00:02:57,440
index value of zero is and the computer will have a score of whatever the score index value one is.

36
00:02:57,740 --> 00:02:58,810
So let's try that out.

37
00:02:58,820 --> 00:03:02,510
So refresh clear that and computer wins.

38
00:03:02,510 --> 00:03:09,700
Player zero, computer one computer wins and we should also output what was selected as well.

39
00:03:09,980 --> 00:03:15,890
So I'm going to simply add to here you're going to take this message updated here, set our message

40
00:03:15,890 --> 00:03:23,210
in HTML computer selected and we'll output whatever the value of the computer guess was to try that

41
00:03:23,210 --> 00:03:23,830
one more time.

42
00:03:24,140 --> 00:03:30,080
So computer selected tales and we need to make this a little bit bigger or we could make it a little

43
00:03:30,080 --> 00:03:30,620
bit smaller.

44
00:03:30,920 --> 00:03:32,780
And we also need some spacing in there.

45
00:03:32,810 --> 00:03:33,890
So some line breaks.

46
00:03:34,520 --> 00:03:37,590
Sometimes you do need to tweak it so the output looks right.

47
00:03:37,610 --> 00:03:39,680
So now we're going to select either heads or tails.

48
00:03:39,830 --> 00:03:44,350
We select heads, computer selected head player wins.

49
00:03:44,360 --> 00:03:46,510
So player has one, computer has zero.

50
00:03:46,550 --> 00:03:48,490
Again, we're going to select heads.

51
00:03:48,740 --> 00:03:54,740
So computer selected heads, player wins, player two, computer one or computer one.

52
00:03:54,740 --> 00:03:58,190
Now because the computer just one because computer selected tails.

53
00:03:58,580 --> 00:04:00,140
So quick little minigame.

54
00:04:00,410 --> 00:04:01,910
Go ahead and try it out for yourself.

55
00:04:02,150 --> 00:04:08,120
Add in the final logic and you need to play through it in order to make sure that everything is working

56
00:04:08,120 --> 00:04:09,110
as intended.

57
00:04:09,290 --> 00:04:14,030
So there's usually a few play through at the end where you can make some tweaks and adjustments as needed.

58
00:04:14,150 --> 00:04:15,770
So go ahead and try it out for yourself.

59
00:04:15,770 --> 00:04:19,820
Add this into your own project and see what you can make happen with JavaScript.
