‫Welcome back to the second.
‫If statements challenge the high score challenge, I hope you manage to solve the issue and write your
‫code.
‫And in this video I'm just going to show you how I would solve it.
‫And as usual, there are multiple different approaches to solving this challenge.
‫So first of all, I create variables.
‫So the first one is going to be a static int high score, which I'm going to set to 300.
‫So the old high score was 300, now static string, high score player.
‫So that's the person who holds the high score.
‫And I'm just going to say it's me.
‫So my high score is 300.
‫Now I need to create a method which checks if the new score by a player is higher than the high score.
‫And I do that best with a public static void check, high score method.
‫And then here I need two parameters.
‫One of them is the score, so I'm going to say in score and the other one is a string, which is the
‫player name.
‫And in here what I want to do is I want to check if the score of the player is higher than the high
‫score.
‫So if score higher, high score, then go ahead and update the old high score with the score and also
‫update the high score player with the player name high score player is equal to player name.
‫Now I also want to inform the console about that.
‫So let's update that onto the console as well or write it on the console.
‫And I'm just going to write something like New High Score is and score
‫and console dot right line
‫it is now held by and let's write by whom is held it's by player name.
‫So the player who broke the record is going to be written on there as well.
‫And also the high score player is overridden.
‫So in both cases you could have either use score and player name or high score and high score player
‫because those two are updated already.
‫Now we have our if statement.
‫Let's go with the else.
‫So what should happen if the score is not higher than the old score?
‫Well, we simply write onto the console right line.
‫The old high score could not be broken.
‫It is still.
‫And then the high score and held by and then the player who holds it.
‫So here we need a plus as well.
‫So what I'm going to do is in order to make it more readable, I'm going to put it into the next line
‫and by the high score player.
‫So that's pretty much it.
‫That's our check high score method.
‫So this method is always going to check if the score is given as an argument is higher than the old
‫score.
‫And if it is, then we simply update the high score.
‫And we also write Who was the player who broke the score?
‫So now in order to figure out if a player has broken the score, we also need to call this method,
‫of course.
‫So I'm going to call this method in here, and I'm going to start off with a value of 250, which was
‫achieved by Maria.
‫And then we have another one.
‫Let's go with 315 by Michael.
‫And then I saw that Michael broke my high score.
‫So I went in and broke my own as well.
‫So I made 350 points and so I'm the high score leader again.
‫That's highly important to me.
‫That's why I do it now.
‫Just kidding.
‫So then what we have next is to write that onto the console.
‫So console, dot read.
‫So we do write it by calling these methods, but we don't see it unless we make the console stall.
‫So we need to use the read method here so that we are the old high score could not be broken.
‫It's still 300 and held by tennis.
‫Then the new high score is 350.
‫It is now helped by Michael.
‫New high score is 350.
‫It is now held by Dennis.
‫So now you see how you can.
‫Quite easily create a functionality that checks if a high score is broken or not.
‫And you could simply update, well, if you have a bigger game, let's say you could easily update the
‫high score now and well, always show the latest and greatest high score.
‫All righty.
‫I hope you manage to do that yourself.
‫There are not too many tricky things.
‫It's pretty much only things that we have covered in this chapter and before.
‫So now you have created your own method.
‫You have used if an LS and you call it the method and you even use global variables and local variables.
‫Now, we haven't used global ones, but we have used parameters.
‫Great.
‫So see you in the next video.