-: Now one more thing that we do kind of wanna explore is,
well, can it also write code to play a game?
So let's say like, could you write code that plays a game
of let's say, Rock Paper Scissors?
It's able to do that. Sure enough.
It's gonna give us some code generation here.
Here is a JavaScript file that gives us a function
of how we could do this.
And so one thing that's kind of cool about browsers is
that we can actually go into our console
and start writing JavaScript
and actually executing it in here too.
So if I actually go ahead
and copy this code once it's done generating
and pull it into the console here,
it's actually its own runtime.
So if we go ahead
and copy that function in, we've declared this function.
So now we're gonna actually call that function.
Like so.
And sure enough, we've got this prompt up here saying,
choose rock, paper, scissors.
Let's go ahead and say rock.
And we won somehow for the rules
of Rock Paper Scissors, rock beat scissors.
So we won. That's kind of cool.
Let's see if I can try to get a tie or a loss or something.
Let's just go ahead with paper.
Oh, I won again. Maybe I'm just too good at this game.
But yeah, so we can see it even goes ahead
and describes what it's doing in here.
So if you're not familiar with coding, it explains exactly
what it just wrote in terms of code
and how it used the math random function to select a choice
for the computer, right?
We can see here that the computer choice is being picked
from this math function that's generating a random number,
multiplying it by three,
and then flooring it to get one of the indices
of this options array.
If you're unfamiliar with any of the terms I just said,
those are some pretty basic computer science principles
and you could ask ChatGPT about any of those
and I'm sure it'll give you a great description
of what those are, how they kind of interact in the code.
You can go down the rabbit hole, right?
Like you can ask it to clarify
what it meant by a certain thing.
And now this is of course,
not an introductory computer science,
but how we can use ChatGPT to learn how to code,
to write code for us, to document our code,
generate code, all those sort of things.
And we could even go one step further
and maybe even ask it to bring this game into our React app.
Could you bring that Rock Paper Scissors game
into my React app?
And let's see if it's able to do that.
That seems like a pretty challenging thing.
I'd be pretty surprised if it could do it,
but sure enough, it does say it's able to do it.
So there really is no limit
to what you can ask this thing
if it's probably above some sort of confidence threshold
that it can answer your question,
it's gonna go ahead and tell you right,
that it's able to do it.
So maybe blindly we'll just go ahead
and copy this in for fun just
to see if it'll actually work or not.
But yeah, this is kind of just experimenting at this point
to see if this will actually work.
So yeah, so you can see there's a lot
of striking similarities between the code
that we had just written or just been generated
for this game.
And it's right here, except now it's being declared
as the function under play game.
And yeah, so we're basically just porting it all
into our React app.
So we're gonna declare this function here in addition
to the other functions we had declared.
And then we're gonna just copy this whole div in as well.
So there is a little knowledge required to know
like what exactly you should be copying in here.
But let's go ahead
and remove that button counter that we just had,
as well as the React app intro stuff
'cause we don't really actually care about that.
We just want a Rock Paper Scissors.
And, whoa, that actually works.
So we now have a Rock Paper Scissors website.
Choose your weapon. Interesting choice of word there.
Let's go ahead and say rock.
You chose rock, the computer chose rock.
It's a tie.
Paper.
You chose paper, the computer chose rock.
You win.
Well, okay, I guess this game really doesn't want me
to lose, but the computer's just going really easy
on me today.
But as you can see, as long as you have an idea,
ChatGPT can make it come true.
And that's a really beautiful thing about using this, right?
Like honestly, this is pretty mind blowing even
to someone in the computer science field.
So yeah, as long as you have an idea of what you want
and you have a little bit of base knowledge about sort
of coding, which ChatGPT can help you get to,
it's really fascinating the amount of things
that ChatGPT can do in a coding perspective.
In the next video we're gonna be talking about algorithms
and how we can use ChatGPT in that realm.