Welcome back.
In this video we're going to set up a quiz application.
And maybe we will need more than just one video.
But I still wanted to build a little quiz app with you.
So let's go ahead and create a new project.
And it's going to be a console app again, I'm going to call this one Quiz app.
And then let's click next and keep the defaults here.
And the quiz app will be quite simple.
So we are going to need the following.
We will need the questions.
We'll need the answers.
And then we will need to ask the user for a question number one.
Then the user can enter something and we will check if the entered value is correct or the same as we
have set up as the answer.
If that's the case, the user gets a score an additional point, so the score goes up by one.
And that means that we're going to need a variable that will store the score as well.
And then at the end we want to display to the user how many points or what the score was that the user
got.
So let's go ahead and start with a few questions.
So for example string question one would be what is the capital of Germany?
As I live in Germany I'm going to say the answer is going to be Berlin, even though the best city is
Cologne, because I live in Cologne.
So then we have a second question and that would be what is two plus two?
Super simple example, but it's really just about the logic behind the code.
Not so much about the difficulty of the questions.
So I'm going to use answer, uh, being a string as well to keep it simple.
And then question number three will be what color do you get by mixing blue and yellow.
And I would say that's green.
So string answer three will be green.
All right.
So this will be our questions.
Then we will need an integer that holds the score.
Then we will need to ask the user the first question.
So question number one.
And then we need to know what the user answer was.
And answer will be console dot read line.
And here we check if the answer one.
Or let's say the user answer one is equal equal to answer one.
If that's the case then we're going to write on the console, not the question, but actually we're
going to write something like correct.
And what do we need to do as well.
If the user has answered correctly, we need to set the score up.
So we will need to set the score to one.
Or we can say score equals score plus one.
I will show you a faster way of writing.
Score equals score plus one in the next video.
But first let's keep it simple for this example.
Then we need to have an else block here as well.
Because if the answer is not the same, then the user was wrong.
So we're going to write on the console something like wrong.
The correct answer is.
And then because it's really simple here I'm just going to use concatenation.
I'm going to say answer one.
It's going to be the right answer okay.
So let's run this and test this before we keep going with our code.
Because that's really good practice in general to first test one thing before keep going with the rest.
So I'm going to say Berlin and my program closes obviously.
So we need to add console dot read key to keep our software running.
So Mouichido there we are.
What is the capital of Germany?
Berlin.
And it says correct.
Perfect.
So now let's run it again and say Berlin.
And it says wrong.
The correct answer is Berlin.
So it really matters if we're using the capital letter or not.
This is something we can fix.
I'm going to show you how we can get our way around it in the next video as well, maybe the video after
the next video.
So now that you know how it works for the first answer, how does it work for the second answer?
Okay, so I'm going to do the same thing.
I'm going to copy this entire code, paste it in here.
And now it's going to be question two.
And we're going to get answer two of the user.
And we're going to do all the same as well as here.
We place this with answer two.
And now we run it once again here for three.
So we replace question one with question three.
User answer one with user answer three as well as here, here, and finally here.
So this will give us three questions with a potential score of three.
So how would we now use this to let.
The user know what their score was.
So I'm going to say something like dollar sign quiz completed and your final score is here.
We're going to say curly brackets score.
So whatever the user had out of three okay.
So in this case we do only have three variants.
So three questions.
Now you could obviously go ahead and say oh we don't have the tools yet.
So right now it's all hard coded.
We will find better solutions later on when we are working with arrays and for statements and all of
the good stuff, we can make this better then.
But for now, this will be good enough.
And now how do we go about telling the user that they were right with all questions so that they got
everything right?
Okay, I hope you paused the video and tried it.
You can pause it now still if you want to try it.
So basically we're going to check if the score is equal to three.
Because if that's the case then we know that the user got all right.
So we're going to say excellent.
You got all the answers right.
And then in the case that the score is greater than zero they at least have something right.
We're going to say something like good job good job but keep learning.
And then finally we have the else block where the user has zero points.
So we're going to say try again and see if you can get some answers right next time.
All right.
And that would be our a little program okay.
So let's run it again and let's check it out Berlin is the capital of Germany.
So we're going to set four as the answer of two plus two.
And you get green when you mix blue and yellow.
And we are quiz completed.
Your final score is three out of three.
Excellent.
You got all the answers right.
Woohoo!
Now let's do it again.
But this time we're going to only have one correct.
So Berlin this one will be five and this one will be something.
And it says wrong.
The correct answer is green and quiz completed.
Your final score is one out of three.
Good job but keep learning okay so that's it for this video.
In the next one, I want to quickly show you how you can do this better okay.
This score plus one.
And then after that we're going to look at how we can make sure that we don't care about capital letters
or lower letters or empty spaces at the end of a entry.
Because for example, if I write Empty Space Berlin, the answer is still correct, right?
But it will say wrong.
The correct answer is Berlin.
Even though I wrote Berlin.
But I had an empty space here, so that's something that is very tricky.
Also, when entering usernames or passwords where for example, you by accident have an empty space
at the end or at the beginning.
This would lead to a bunch of problems, but there is a very simple solution.
So we're going to look at that as well.
So see you in the next video.