1
00:00:00,000 --> 00:00:02,760
-: Now one more thing that we do kind of wanna explore is,

2
00:00:02,760 --> 00:00:05,220
well, can it also write code to play a game?

3
00:00:05,220 --> 00:00:10,110
So, let's say like, could you write code that plays a game

4
00:00:10,110 --> 00:00:12,543
of let's say rock paper scissors?

5
00:00:14,070 --> 00:00:15,510
It's able to do that, sure enough.

6
00:00:15,510 --> 00:00:17,760
It's gonna give us some code generation here.

7
00:00:18,840 --> 00:00:23,100
Here is a JavaScript file that gives us a function of

8
00:00:23,100 --> 00:00:25,443
how we could do this.

9
00:00:26,970 --> 00:00:31,560
And, so one thing that's kind of cool about browsers

10
00:00:31,560 --> 00:00:35,010
is that we can actually go into our console

11
00:00:35,010 --> 00:00:37,170
and start writing JavaScript,

12
00:00:37,170 --> 00:00:39,450
and actually executing it in here too.

13
00:00:39,450 --> 00:00:42,630
So, if I actually go ahead and copy this code,

14
00:00:42,630 --> 00:00:43,650
once it's done generating,

15
00:00:43,650 --> 00:00:45,630
and pull it into the console here,

16
00:00:45,630 --> 00:00:47,670
it's actually its own runtime.

17
00:00:47,670 --> 00:00:51,180
So, if we go ahead and copy that function in,

18
00:00:51,180 --> 00:00:52,800
we've declared this function.

19
00:00:52,800 --> 00:00:55,260
So, now we're gonna actually call that function.

20
00:00:55,260 --> 00:00:59,340
Like so, and sure enough we've got this prompt up here

21
00:00:59,340 --> 00:01:00,930
saying choose rock, paper, scissors.

22
00:01:00,930 --> 00:01:02,730
Let's go ahead and say rock.

23
00:01:02,730 --> 00:01:04,709
And we won, somehow, for the rules

24
00:01:04,709 --> 00:01:06,720
of rock paper scissors, rock beat scissors.

25
00:01:06,720 --> 00:01:08,250
So we won. That's kind of cool.

26
00:01:08,250 --> 00:01:11,823
Let's see if I can try to get a tie or a loss or something.

27
00:01:13,680 --> 00:01:15,900
Let's, let's just go ahead with paper.

28
00:01:15,900 --> 00:01:17,820
Oh, I won again, maybe I'm just too good at this game.

29
00:01:17,820 --> 00:01:19,620
But yeah, so we can see,

30
00:01:19,620 --> 00:01:22,320
it even goes ahead and describes what it's doing in here.

31
00:01:22,320 --> 00:01:24,270
So, if you're not familiar with coding,

32
00:01:25,230 --> 00:01:28,960
it explains exactly what it just wrote in terms of code,

33
00:01:28,960 --> 00:01:33,600
and how it used the math random function to select a choice

34
00:01:33,600 --> 00:01:35,550
for the computer, right.

35
00:01:35,550 --> 00:01:38,370
We can see here that the computer choice is being picked

36
00:01:38,370 --> 00:01:42,120
from this math function that's generating a random number,

37
00:01:42,120 --> 00:01:44,340
multiplying it by three, and then flooring it to get one

38
00:01:44,340 --> 00:01:47,310
of the indices of this options array.

39
00:01:47,310 --> 00:01:48,660
If that sounds,

40
00:01:48,660 --> 00:01:50,820
if you're unfamiliar with any of the terms I just said,

41
00:01:50,820 --> 00:01:53,190
those are some pretty basic computer science principles,

42
00:01:53,190 --> 00:01:56,400
and you could ask ChatGBT about any of those,

43
00:01:56,400 --> 00:01:58,080
and I'm sure it'll give you a great description

44
00:01:58,080 --> 00:02:01,650
of what those are, how they kind of interact in the code.

45
00:02:01,650 --> 00:02:03,240
You can go down the rabbit hole, right.

46
00:02:03,240 --> 00:02:04,740
Like, you can ask it to clarify

47
00:02:04,740 --> 00:02:06,900
what it meant by a certain thing.

48
00:02:06,900 --> 00:02:07,733
And now, this is a course,

49
00:02:07,733 --> 00:02:09,000
not on introductory computer science,

50
00:02:09,000 --> 00:02:12,690
but how we can use ChatGBT to learn how to code,

51
00:02:12,690 --> 00:02:14,940
to write code for us, to document our code,

52
00:02:14,940 --> 00:02:16,560
generate code, all those sort of things.

53
00:02:16,560 --> 00:02:18,360
And, we could even go one step further,

54
00:02:18,360 --> 00:02:23,360
and maybe even ask it to bring this game into our React app.

55
00:02:23,760 --> 00:02:28,170
Could you bring that rock paper scissors game

56
00:02:28,170 --> 00:02:30,153
into my React app?

57
00:02:31,770 --> 00:02:33,450
And, let's see if it's able to do that.

58
00:02:33,450 --> 00:02:35,280
That seems like a pretty challenging thing.

59
00:02:35,280 --> 00:02:37,080
I'd be pretty surprised if it could do it,

60
00:02:37,080 --> 00:02:40,860
but sure enough, it does say it's able to do it.

61
00:02:40,860 --> 00:02:43,380
So, there really is no limit to

62
00:02:43,380 --> 00:02:45,870
what you can ask this thing if it's

63
00:02:45,870 --> 00:02:47,610
probably above some sort of confidence threshold

64
00:02:47,610 --> 00:02:49,260
that it can answer your question,

65
00:02:49,260 --> 00:02:50,910
it's gonna go ahead and tell you, right,

66
00:02:50,910 --> 00:02:52,470
that it's able to do it.

67
00:02:52,470 --> 00:02:54,780
So, maybe blindly we'll just go ahead and copy

68
00:02:54,780 --> 00:02:58,590
this in for fun just to see if it'll actually work or not.

69
00:02:58,590 --> 00:03:02,363
But yeah, this is kind of just experimenting at this point

70
00:03:02,363 --> 00:03:05,820
to see if this will actually work.

71
00:03:05,820 --> 00:03:07,800
So yeah, so you can see there's a lot

72
00:03:07,800 --> 00:03:09,570
of striking similarities between the code

73
00:03:09,570 --> 00:03:12,270
that we had just written, or just been generated,

74
00:03:12,270 --> 00:03:13,410
for this game.

75
00:03:13,410 --> 00:03:15,780
And, it's right here except now it's being declared

76
00:03:15,780 --> 00:03:17,940
as the function under play game.

77
00:03:17,940 --> 00:03:21,990
And yeah, so we're basically just porting it all into

78
00:03:21,990 --> 00:03:23,310
our React app.

79
00:03:23,310 --> 00:03:25,533
So we're gonna declare this function here,

80
00:03:26,370 --> 00:03:29,340
in addition to the other functions we had declared.

81
00:03:29,340 --> 00:03:33,900
And then, we're gonna just copy this whole div in, as well.

82
00:03:33,900 --> 00:03:36,450
So, there is a little knowledge required to know like

83
00:03:36,450 --> 00:03:39,240
what exactly you should be copying in here.

84
00:03:39,240 --> 00:03:42,090
But, let's go ahead and remove that button counter

85
00:03:42,090 --> 00:03:45,660
that we just had, as well as,

86
00:03:45,660 --> 00:03:48,810
the React app intro stuff,

87
00:03:48,810 --> 00:03:50,160
'cause we don't really actually care about that.

88
00:03:50,160 --> 00:03:51,658
We just want our rock paper scissors.

89
00:03:51,658 --> 00:03:52,770
And,

90
00:03:52,770 --> 00:03:54,900
whoa, that actually works.

91
00:03:54,900 --> 00:03:57,750
So, we now have a rock paper, scissors website.

92
00:03:57,750 --> 00:04:01,290
Choose your weapon, interesting choice of word there.

93
00:04:01,290 --> 00:04:02,700
Let's go ahead and say rock.

94
00:04:02,700 --> 00:04:04,770
You chose rock, the computer chose rock, it's a tie.

95
00:04:04,770 --> 00:04:08,250
Paper, you chose paper, the computer chose rock, you win.

96
00:04:08,250 --> 00:04:09,480
Wow, okay, I guess this game really

97
00:04:09,480 --> 00:04:11,010
doesn't want me to lose, but...

98
00:04:11,010 --> 00:04:13,110
Or the computer's just going really easy on me today.

99
00:04:13,110 --> 00:04:14,760
But, as you can see,

100
00:04:14,760 --> 00:04:18,720
as long as you have an idea, ChatGPT can make it come true.

101
00:04:18,720 --> 00:04:21,959
And that's a really beautiful thing about using this, right?

102
00:04:21,959 --> 00:04:25,860
Like honestly, this is pretty mind blowing even to someone

103
00:04:25,860 --> 00:04:27,360
in the computer science field.

104
00:04:28,200 --> 00:04:30,750
So yeah, as long as you have an idea of what you want

105
00:04:30,750 --> 00:04:33,630
and you have a little bit of base knowledge about

106
00:04:33,630 --> 00:04:36,693
sort of coding, which ChatGPT can help you get to.

107
00:04:37,560 --> 00:04:39,930
It's really fascinating the amount of things

108
00:04:39,930 --> 00:04:42,720
that ChatGPT can do in a coding perspective.

109
00:04:42,720 --> 00:04:44,940
In the next video, we're gonna be talking about algorithms,

110
00:04:44,940 --> 00:04:47,883
and how we can use ChatGPT in that realm.

