1
00:00:00,300 --> 00:00:06,300
In the previous lesson, we showed you how we can set up the player selection and track that information,

2
00:00:06,630 --> 00:00:12,620
and then earlier we also saw how we can generate a random selection for the computer play.

3
00:00:13,170 --> 00:00:17,520
Now we need to compare both of those results and determine who wins.

4
00:00:17,910 --> 00:00:23,280
So setting up a variable, we're going to call it result, and we're going to link that to a function

5
00:00:24,000 --> 00:00:26,520
that we're going to create, which will be check winner.

6
00:00:26,760 --> 00:00:29,430
We need to pass in some values into it.

7
00:00:29,760 --> 00:00:33,950
So one of the values that we need to pass in is the player selection.

8
00:00:34,230 --> 00:00:35,940
So let's set up a variable for that.

9
00:00:35,940 --> 00:00:41,640
So player selection, and that's going to equal to what we were originally outputting into the console.

10
00:00:42,030 --> 00:00:44,220
And we saw that earlier as rock.

11
00:00:44,370 --> 00:00:47,960
And then we also saw that the computer selection is there as well.

12
00:00:48,300 --> 00:00:54,240
So taking the player selection and it actually doesn't matter which one is first, it will differentiate

13
00:00:54,240 --> 00:00:55,140
between the logic.

14
00:00:55,380 --> 00:00:57,930
So we've got player selection and computer selection.

15
00:00:58,200 --> 00:01:06,300
We need to pass both of those values into our result function in order to be able to check those values

16
00:01:06,480 --> 00:01:07,950
and determine a winner.

17
00:01:08,190 --> 00:01:10,970
And that means that we need to create a function for this.

18
00:01:11,400 --> 00:01:14,730
So creating a function, we're going to call it check winner.

19
00:01:15,240 --> 00:01:18,090
And within this function, we've got two parameters.

20
00:01:18,480 --> 00:01:23,100
So we've got the player and we've got the computer and we need to do a comparison.

21
00:01:23,580 --> 00:01:27,420
And this is going to be quite a few different conditions that we're checking.

22
00:01:27,660 --> 00:01:32,790
So we're checking to see if the player is equal to the computer selection.

23
00:01:33,030 --> 00:01:38,700
And if it is, then we're going to simply return back a draw, the return back, the word draw.

24
00:01:39,000 --> 00:01:45,410
And I'm going to also add in one more line here where we're going to log out the results of result.

25
00:01:45,420 --> 00:01:46,850
So that was the first condition.

26
00:01:47,190 --> 00:01:51,500
So that takes care of if both of them are matching the next one.

27
00:01:51,510 --> 00:01:59,760
Let's check to see if the player has selected rock, if the player has selected rock, that we know

28
00:01:59,760 --> 00:02:06,150
that the computer will lose if the computer has selected scissors.

29
00:02:06,480 --> 00:02:10,490
But we know that the computer will win if he is selected paper.

30
00:02:11,280 --> 00:02:18,060
So we're going to check to see if the computer has selected paper and we're going to do all of this,

31
00:02:18,060 --> 00:02:20,400
all of the logic here by wind conditions.

32
00:02:20,700 --> 00:02:27,600
So if the computer selected paper, the player selected Rock, we're going to return back the computer.

33
00:02:27,630 --> 00:02:28,710
So that's going to be the winner.

34
00:02:28,930 --> 00:02:32,010
And we're was going to return back the string of whatever the winner is.

35
00:02:32,130 --> 00:02:37,620
And if it's not a computer, then we're going to return back the player.

36
00:02:38,100 --> 00:02:43,020
And the reason here is that the player is going to be the winner in this scenario.

37
00:02:43,440 --> 00:02:49,050
So unless the computer has returned back, rocked the only other choice, because we've already taken

38
00:02:49,050 --> 00:02:51,950
the condition checking for a draw.

39
00:02:52,260 --> 00:02:54,540
So that means that they're not both the same.

40
00:02:54,720 --> 00:03:01,770
The player selected rock, and the only other choice is that the computer selected, if it didn't select

41
00:03:01,770 --> 00:03:04,890
Rock, if it didn't select paper, then it selected scissors.

42
00:03:04,890 --> 00:03:07,170
And that means that the player one condition.

43
00:03:07,200 --> 00:03:09,090
So this one is going to be very similar.

44
00:03:09,270 --> 00:03:11,370
And this is the other alternative.

45
00:03:11,550 --> 00:03:18,600
If a player selected paper, we're going to check to see what the computer selected.

46
00:03:19,320 --> 00:03:21,690
So the same format as just above.

47
00:03:22,050 --> 00:03:28,440
We're going to check to see if the computer selected scissors and if the computer selected scissors,

48
00:03:28,590 --> 00:03:30,510
then that means that the computer wins.

49
00:03:30,630 --> 00:03:34,950
And if the computer didn't select scissors, there's only one last option.

50
00:03:35,100 --> 00:03:39,780
And that means that the player won because the computer selected rock.

51
00:03:40,740 --> 00:03:41,580
So refresh.

52
00:03:42,520 --> 00:03:49,720
Refresh it and we'll hit rock, so we selected Rock, the computer selected paper, and that means that

53
00:03:49,720 --> 00:03:52,650
the computer won because the paper beats the rock.

54
00:03:52,720 --> 00:03:53,910
Well, try rock one more time.

55
00:03:55,510 --> 00:04:02,140
We see we both selected rock, so it returned back to draw, and this time we selected Rock Computer,

56
00:04:02,140 --> 00:04:03,370
selected scissors.

57
00:04:03,550 --> 00:04:05,120
So that means that we were the winner.

58
00:04:05,170 --> 00:04:08,290
So that was a nice selection of all the different options.

59
00:04:08,410 --> 00:04:11,900
And we could try the same thing for paper again, paper draw.

60
00:04:12,080 --> 00:04:16,840
It's always a good idea to play through it a little bit just to make sure that your logic is working,

61
00:04:16,840 --> 00:04:20,970
it's being applied properly and that you are returning back the correct winner.

62
00:04:21,130 --> 00:04:26,440
Remember again that the order here is important if you switch it around in this logic isn't going to

63
00:04:26,440 --> 00:04:32,500
work and you have to switch these values around as well, or you can switch around some of the logic.

64
00:04:33,380 --> 00:04:38,900
So go ahead and add this into your project, try it out and make sure that you are returning the correct

65
00:04:38,900 --> 00:04:43,760
winner and you can be ready to move on to the next step where we're going to be associating score and

66
00:04:43,760 --> 00:04:46,540
outputting who the winner is to the player.

67
00:04:46,730 --> 00:04:48,790
So that is all still yet to come.
