OK, here we are back in VS code, so let's work up an example.
So in this example, we're going through a menu and we're ordering something off the menu.
So at the end, we want to check with the user and make sure that they don't want to order something
extra.
So we'll say something like,
let's prompt or not prompt.
What answer equals prompt on?
What size price?
Would you like.
And I've got the team take to work very well, and then down here will say, yes, answer equals small,
we'll say
I'm going to do this all night in the council.
So we'll say answer equals I will say confirm this time.
Confirm small is not very much.
Are you sure?
And if answer is true, will go on otherwise then we'll ask them what size would you like that.
So absolutely false in this case.
We'll say not answer.
And by the way, I should be using a triple equals sign up here to check the type as well.
So we'll say, if not, answer.
We'll say answer equals prompt,
would we go confirm?
Would you like large?
And then we'll say, let's see here will say, well, credit variables say a lot of fry size of the
Y equals zero, where zero means they don't want any fries, one too small to medium and three is large.
And so then we'll say, would you like large?
They do want a large B three.
Otherwise it's going to be two because the only choice is medium.
So we'll say if you answer.
And then we'll say fry size equals three
else, fry size equals two, and then the all the way back here where we didn't confirm this, it's
always better to have a positive answer or positive checks are going to change this to true.
And all this down here will make into a fall or into an else.
So if they are sure they want small, we'll make the prices be three, I'm sorry, one.
And then also I will say we won't bother to ask them if they say medium or if they say large, we'll
just assume that that's OK.
So we'll say, oh, if answer equals medium.
Frame size equals to.
Else, what would you say else, there's no other choices else prices equals three.
And then down here at the bottom, we'll just toss up an alert.
And we'll deal with the templating your price size is.
Process.
All right, so we got a little program here that does a couple of things.
So let's go ahead and run it and.
So what size fries would you like?
So let's just say a large quick, OK, tossed out there, your fries houses three.
Let's run it again.
We say medium.
It says your price rises, too.
If we say small, small is not very much.
Are you sure?
We will say cancel means not sure in this case.
Would you like a large number or a large difference sizes too.
So you can see a confirm is a little bit a little bit difficult on that as far as the prompt.
Can you change the prompt?
I don't remember now.
It doesn't look like.
All right, so we've got this little thing in here where we're checking the prices and it can be small,
medium or large.
Now, there's a little problem here, which is that if you don't type in the answer.
Exactly, it's going to give you well, it's probably going to give you large.
So if I say I want small without an uppercase, yes, it's going to fall all the way through to the
house and say, hey, you wanted a large which is maybe not what the user wanted it.
Right.
So we can build in a little bit more better air checking into this, too.
So they only give the answer that that they're supposed to give.
So let's do that a little bit differently and say, what size fries would you like?
And we'll give them more limited choices of what they can enter.
So we'll say as equals more
and equals medium now equals large.
All right.
So we're going to have them enter the S, M or L instead.
So let's change this to S, let's change this to M and let's go ahead and change this.
So we do the check.
The answer equals L.
All right, so let's try that and see what happens.
What size, Farai, would you like as equal, small and medium, Alekos, large, yes.
Your friend has a zero because if all the way through and it didn't find anything, so there are no
fries.
So our first problem is that our answers equals an uppercase value.
So one way we can handle this is by using an R so we can say or
answer equals a little less
and then think that here.
But I'm not going to change it for right now.
Right now, I find a little less that's going to go into the small logic.
Are you sure?
OK, Fry says one we order a large.
OK, another way to handle this would be with a switch statement instead of these ifs.
The problem with a bunch of this when you have different cases is it starts getting complicated.
Switch statement will make it a little bit simpler so you can do any switch statement with ifs.
But switch statement is better if you have a certain set of answers that you're going to get.
So we'll say switch
answer.
And then here we'll say case.
Yes,
case a little less.
And when you get a curly brace.
And we get down in the end of this and we say break and then down here case and.
Case little in and we get rid of this stuff and we also want to get rid of this extra curly brace and
we'll get rid of this stuff and at the end of this Christmas break,
and then instead of this, we want to say.
Case, Al.
Case a little while and at the end of this, we want to say break and then we going say default.
No fries ordered,
and then we ended up with the curly fries.
Now a lot of times Vaskov will organize your coat for you when you finalize a curly brace, but it did
do it in this case.
So I'm going to give you a shortcut to reorganize all your code so you lose you hold down the control
key.
This is on Windows.
It might be different on a Macintosh or Linux, but you do control a which is to select all and then
control still holding down the control k f and reformats your code.
So now everything is indented correctly.
So here we have a case statement that does this.
So that's kind of nice.
So let's save that and let's run.
It was a surprise.
Would you like to say a little as small as.
Not very much.
Are you sure.
I say cancel and it says, would you like large?
Why is it asking me would you like large?
Oh, oh, because I said that I don't want the small, so we'll say, OK, your price has just three,
that's fine.
So this solves it, but we can make it even a little bit simpler.
If we said, if you recall correctly, on the two string, there's a two on the on the string, there's
a two upper second say to upper case.
So we we change the diaper case so we can get rid of the little the little characters.
And that makes our program a little bit simpler.
So all we have is S, M and L and no fries ordered.
So it should work exactly the same
medium and taking a lower case m different sizes too.
OK, let's thing, let's use the ternary operator to handle the the size down here.
So we're going to embed a couple of things and we'll do it as a separate statement.
We'll say let's bring in a conflict because we're not going to change it.
Costed Fahri size name equals.
So the price size is one, it's large.
So we'll say fry size properly equals one then large and then we could say else something else.
But we need to check if it's two or three and we also need to check on the zero.
So this can be sort of the complicated ternary.
So let's just start with this and say if it's one that is large, otherwise it's medium and that's not
right.
But we'll make it more complicated in just a second.
So we'll say you are a large Frazetta three, and that's because I did not put the price his name in
here.
So if assizes million, let's say I've got it backwards, largest three.
Let's try one more time
right now.
If ISIS is like anything else better, it's can be media.
So fighter.
Q Let's just say, I guess the president, because it goes the alert first and then once he's done with
that, it says your privatizes media.
All right.
So one thing we can do since we get this alert here, if we don't get a good process, is we can say
if Fahri size is greater than or equal to one and Frys size is less than or equal to three.
So that way we won't get a double message on that.
And again, you can see it in dance.
So I'm just going to do the control AK and it will reorganize everything.
So now we're only doing this for the large and medium.
So on the medium side, what we'll do is go down to a new line.
Why do that?
I'd like to indent so on.
The new line will say if the fray size equals to that, it's a medium, otherwise small.
And when you start doing this with the ternary operator, it's probably better put parentheses around
their here so it doesn't mistake you.
Don't make a mistake on what you're doing now with it only gets grouped together.
All right.
Is that right?
How the world will say to you, why are we getting no prize or because I said to get my own rules,
I am different sizes, medium sized again and small.
Are you sure?
OK, for our size as small as brown one more time or small.
Are you sure?
No.
We like a large size is large.
And again, if we enter a bad entry like, you know, fries ordered and it's not going to give us the
second message this time.
So anyway, that is an introduction to the conditionals using relational operators and logical operators,
and that really helps build out our programming examples.