This lesson, we're going to be putting the final touches on our accomplis, we come in as the player
has to select either heads or tails, they select heads or tails, and then the computer randomly generates
either heads or tails.
If they selected correctly and got the same answer that the computer got, then they're going to get
a point.
If they got the wrong answer, if they made the wrong selection, then they are they are not going to
get a point and the computer is going to get a point.
So our logic is fairly straightforward in this game because we can use a conditional statement to check
if the player's response is equal to the response of the computer.
And if it is, then this is a win.
And if it's not, then it's a loss and we can use an awful statement in order to handle all of that.
Also, another thing that usually I like to do is to shorten some of the content here so we can have
a player guess value and more meaningful variables as well.
So add that in as the player gets.
And we can also set one up for the computer guess as well, so that we have more of a meaningful variable
name as to what these values are.
So that's the player, guess that's the computer, guess now we can compare if the player guess is equal
to the computer, guess then we have a win, otherwise we have a loss.
Also, let's set up some scoring, and this is actually needs to be Aulet, because the value will change.
So we've got our score creating an array because we've got two players here.
We've got the computer and we've got the player.
So one of them will be the first one and the other one will be the second.
Now, going into here, we can take that value of score, take the first one and we'll increment it
by one.
And if it's a loss, then we're going to do the opposite and we're going to increment the score with
index one.
We will also output those score values.
So using the message, we can add that in our HTML so we can set that into player and also setting up
a default variable here.
So default output.
And then once we get that condition, we can set a value that player wins, otherwise the output will
be equal to computer wins and now we can output that content into the inner message there.
Let's add a new line.
So line break there and we can have the score values so the player will have a value of whatever score
index value of zero is and the computer will have a score of whatever the score index value one is.
So let's try that out.
So refresh clear that and computer wins.
Player zero, computer one computer wins and we should also output what was selected as well.
So I'm going to simply add to here you're going to take this message updated here, set our message
in HTML computer selected and we'll output whatever the value of the computer guess was to try that
one more time.
So computer selected tales and we need to make this a little bit bigger or we could make it a little
bit smaller.
And we also need some spacing in there.
So some line breaks.
Sometimes you do need to tweak it so the output looks right.
So now we're going to select either heads or tails.
We select heads, computer selected head player wins.
So player has one, computer has zero.
Again, we're going to select heads.
So computer selected heads, player wins, player two, computer one or computer one.
Now because the computer just one because computer selected tails.
So quick little minigame.
Go ahead and try it out for yourself.
Add in the final logic and you need to play through it in order to make sure that everything is working
as intended.
So there's usually a few play through at the end where you can make some tweaks and adjustments as needed.
So go ahead and try it out for yourself.
Add this into your own project and see what you can make happen with JavaScript.