Welcome back.
Now let's take care of actually also displaying the result.
So we need to collect the result.
We need to know how many correct answers we gave.
And therefore we need to collect a score or use a score variable which we can increment each time that
we are correct.
Okay.
So let's go ahead and just add a private int score.
Very simple variable.
Now you could use an underscore here to make sure that we understand that it's a private int.
And you could do the same for this private question here if you really felt like it.
So it's really up to you.
It is as we've seen earlier and the naming conventions, it is common to use it this way.
So let's actually do that.
And while doing so let's rename this variable.
So therefore I'm going to go over this here and I'm going to say rename.
And I'm going to add an underscore here.
And then it will be renamed throughout the entire application.
So now let's go ahead and use a score here.
So this field score private INT score.
What it will do is it will be set to zero.
So what we're going to say is each time that we run the app from new, we're going to assume that there
was no score coming from before.
So we're going to set that to zero.
Now when is a good spot to increment the score.
And that's when we are correct.
So in this if statement is correct answer, that's where we can increment the score by one okay.
So underscore score plus plus.
And then we need to display the results.
So therefore what I'm going to do is I'm going to create another method private void display results.
Now in here I'm going to use a logic where I get the percentage of correct answers so to speak okay.
So how can we do that?
Well first of all what I'm going to do is I'm going to have this big text here which says results.
Okay.
So you can copy it from the code that you can download.
But then on top of that I'm just going to display the user score.
So we can just say something like so quiz finished your score is and then display the underscore score
okay.
So you could leave this part out with this results and stuff I just think it looks nice.
So feel free to do it or leave it out.
And then we're going to say out of questions dot.
And actually I need to use a curly brackets here.
Again out of questions dot length.
So out of how many questions did we get.
As many.
So we got let's say two out of five okay.
So this is what this line of code will say.
And then based on whether we actually had a really good score or a mediocre score or a bad score, we're
going to display it accordingly on the screen.
So what I'm going to say is I'm going to have a percentage, which will be the underscore score divided
by question dot length.
So questions dot length.
So however many questions we had.
Now the thing is questions dot length is not a double.
So I need to make those a double like so.
So whatever the result of this division will be it should be a double in the end.
And then what I'm going to what I'm going to check is if percentage is greater than let's say greater
equal 0.8, then I'm going to display in a specific color.
So console dot foreground color.
And I'm going to use green here.
So when everything is right we're going to use green.
And then I'm going to display excellent work.
So CW excellent work.
And then if the percentage is lower so else if percentage is greater equal 0.5.
For example I'm going to use yellow here.
And I'm going to say good effort.
And in the final else if block where we had less than 50% correct.
So less than 0.5 or just the else block actually that would be enough as well.
Just in the else block I'm going to use the red color and I'm going to say keep practicing practicing
practicing English language difficult.
So then we can say console dot reset color here as well.
So I'm setting the foreground color accordingly, displaying whether they should improve or whatever
the player.
And then we're resetting the color so the rest is written in white color again.
So that will be our display results method.
So that's as simple as that.
So when would be a good spot to display the results.
Well I would say after we started the quiz and we've gone through every single question because then
we know how many points we have and all of that.
So we can just.
Display the results down here inside of our start quiz, and that should do the trick.
So let me just go over to my program CSS file and add a few more questions.
You could obviously have nicer, let's say, ways of getting your questions.
You could get them from a file, you could get them from the database or something like that.
But at our current point of the application, we're not ready yet.
So the next question was who wrote hamlet or in brackets here?
Hamlet like so.
And then the options should be gutter.
I'm not sure whether it will understand the issue, so let's use goo.
Great.
Then we have Shakespeare, then, uh, we have Austen and Dickens.
So for those who know a bunch, it would be interesting.
So here again, let's actually put Shakespeare as third option and Austen here because otherwise the
correct answer index would always be one.
So I think it would be a little boring.
And there we are.
So we have our little application.
Let's run it.
And let's see your answer.
Let's say let's make a bunch of mistakes.
So one zero and oh actually I cannot enter zero huh.
So let's enter one again and one.
And we see our results are zero out of three.
Keep practicing.
Now let's make one mistake.
Actually let's have two correctly and one wrong.
So we have Berlin.
We have two plus two equals four.
And here let's say it's gutter.
And then we see good effort.
So now the text is yellow.
And now let's run it again and do no mistakes at all.
So two then two once again.
And here it was three.
And then we see excellent work I think there is an L missing.
So yeah that's pretty much our application done except for I need to learn spelling.
So keep practicing.
And here I think excellent is written like this right.
Yeah.
So I would say that's pretty much our application.
What do you think.
Did you enjoy building it.
Do you have a bunch of really cool questions that you want to display?
Did you modify the app to a degree where it looks even better, even cooler?
Please let me know in the comments and or in the the Q&A section, and I'd be super happy to see what
you build there.
And I wish you all the best with your new knowledge.
The cool thing is, we really used so much out of the things that we have covered so far, where now
you're getting more and more of a feeling for it, so there's always a little bit of something new,
but then also a bunch of stuff that you have seen so far, which really helps you to memorize it even
better.
And it will just keep going like that.
Okay, so thanks for watching and see you in the next video.