1
00:00:02,160 --> 00:00:04,560
Let's work on our game a little bit more.

2
00:00:04,620 --> 00:00:08,680
We get the winner but we get no extra information about the winner, right?

3
00:00:08,700 --> 00:00:13,590
We know that the player won but we don't output any other information.

4
00:00:14,280 --> 00:00:20,880
So what I'll do instead is I'll add more code down there in my game is running logic because I want

5
00:00:20,880 --> 00:00:27,210
to control which message we output to the user. So we can add another if statement here and check if

6
00:00:27,210 --> 00:00:31,920
winner is equal to result draw,

7
00:00:31,950 --> 00:00:34,950
which means we have no winner,

8
00:00:35,190 --> 00:00:37,130
in that case I want to create a message

9
00:00:37,230 --> 00:00:39,540
and actually that message will be different for other cases,

10
00:00:39,600 --> 00:00:44,550
so I'll create it in front of the if statement because as you learned, if you would create it inside of

11
00:00:44,550 --> 00:00:50,430
the if statement, a variable here would only be available in this if block because let and const create

12
00:00:50,430 --> 00:00:52,260
blocks scoped variables.

13
00:00:52,320 --> 00:00:56,730
So in order to have a variable which we can access from any block of our if statement, so also from

14
00:00:56,730 --> 00:01:02,550
the else if branches, we need to create it ahead of time and I'll name it just message

15
00:01:02,550 --> 00:01:10,020
and then here I set message equal to a string created with back ticks, so that I can inject some dynamic

16
00:01:10,020 --> 00:01:19,240
values and there, we can say you picked and then inject the player choice, which will be rock, paper or scissors

17
00:01:20,360 --> 00:01:30,640
and computer picked and then input the computer choice here, therefore you

18
00:01:30,640 --> 00:01:33,840
in this case had a draw, right,

19
00:01:33,840 --> 00:01:35,490
because that's what's happening here.

20
00:01:35,490 --> 00:01:36,630
So that's my message here,

21
00:01:36,630 --> 00:01:38,940
we had a draw.

22
00:01:38,970 --> 00:01:41,190
Now let's move on, in the else if block

23
00:01:41,190 --> 00:01:43,560
here, we can check if winner is equal to result

24
00:01:43,560 --> 00:01:45,650
player wins which means we won.

25
00:01:46,020 --> 00:01:52,110
In this case, I also want to construct a message, so we can actually copy that and yes we could also write

26
00:01:52,110 --> 00:01:54,400
this in a more reusable way,

27
00:01:54,450 --> 00:01:57,190
you could also grab this message here,

28
00:01:57,310 --> 00:02:04,110
cut it and initialize the message up here with that string and only that last part where we have therefore

29
00:02:04,110 --> 00:02:05,310
you

30
00:02:05,310 --> 00:02:07,520
and then here we want to exchange this.

31
00:02:07,530 --> 00:02:17,080
So here, we end with just you whitespace and then here we set message equal to message plus had a draw

32
00:02:17,080 --> 00:02:19,240
in this case to add this and

33
00:02:19,440 --> 00:02:26,140
now here in this else if case, we say won right because the player won here and in the else case which

34
00:02:26,140 --> 00:02:33,640
is that the computer won, we set message equal to message plus lost and we'll only ever make it in one

35
00:02:33,640 --> 00:02:34,420
of these blocks.

36
00:02:34,420 --> 00:02:39,430
So these different parts will not be concatenated after each other but only be added to the space message

37
00:02:39,430 --> 00:02:47,780
here. So with that, we're building that message and I do so, that I can show this to user, by calling

38
00:02:47,780 --> 00:02:55,310
the built-in alert function here, passing message to it and this will show the user that the game

39
00:02:55,310 --> 00:02:57,530
is over and we had a draw, won or lost.

40
00:02:57,530 --> 00:03:03,350
Now since the game is over, I then also want to set game is running to false here which essentially

41
00:03:03,350 --> 00:03:06,520
means we can now click the button again to start a new game.

42
00:03:06,530 --> 00:03:11,570
So here we set it to true and we execute all these steps and then we set it to false again.

43
00:03:11,650 --> 00:03:20,650
So now with that, if we save that, let's go back, reload here, start a game, maybe pick rock and you picked rock,

44
00:03:20,680 --> 00:03:22,010
computer also picked rock

45
00:03:22,030 --> 00:03:22,940
therefore we had a draw.

46
00:03:22,990 --> 00:03:24,190
Okay,

47
00:03:24,430 --> 00:03:27,100
let's start game again which should work now.

48
00:03:27,100 --> 00:03:28,780
Now rock, computer picked paper,

49
00:03:28,840 --> 00:03:30,340
therefore we lost,

50
00:03:30,340 --> 00:03:31,510
makes sense.

51
00:03:31,540 --> 00:03:36,110
Let's start another game, maybe go with paper this time,

52
00:03:36,120 --> 00:03:38,350
computer also picked paper so we had a draw.

53
00:03:38,380 --> 00:03:41,050
So let's go with paper again, another draw,

54
00:03:41,080 --> 00:03:43,550
so let's give that another try

55
00:03:43,810 --> 00:03:46,380
and now we won because the computer picked rock.

56
00:03:46,480 --> 00:03:48,550
So this seems to work, all this logic works,

57
00:03:48,550 --> 00:03:51,730
the game is finished but we're not entirely finished with functions.
