Welcome back, this is less than 11 switched statements, so suwit statements are very similar to IFLA
statements in that you are going to perform different actions based on different conditions, but they're
much more flexible.
The basic keyword will stop the code when the condition is met.
So similar to an if else, you know, one condition can happen.
But the difference here is that with case, you're allowed to do multiple conditions at the same time.
So if it's strawberry or raspberry, then it perform this section of code.
If it's blueberry, this section BEININ in this section and then a switch statement needs a default
at the end, which is like that else in the NFL's.
That will execute a block of code if the conditions are not met.
OK, so let's take a look at it in JavaScript.
All right.
So let's start with.
Start with a contest, fruit is strawberry, and let's do our switch case, so switch fruit, so it's
going to check the value that set for fruit.
And then in different cases, when we say in English, that's not the case, know we're talking about
different scenarios.
So in the case where it's strawberry, it will move on.
And in the case where it's.
Rasberry.
They will execute this block of code here.
Throughputs.
Is red.
And then we have to break have it jump out of the entire logic at that point, and then we go to case
where blueberry.
Instead, we're going to see blue and then we're going to see a case where banana.
We see a banana is yellow.
And then we have to end it with a default and inside my default, I can say.
I can see I don't know.
I don't know what the color of I don't know what color.
The something is that's come up with another one.
OK, so if this is the case, let's just test it out, see what happens.
Strawberry is red or raspberry.
Is red
a blueberry?
Is blue, banana is yellow, and if I put in some other thing like apple, I don't know what color the
apple is awesome.
So this is exactly what we wanted to see.
As you can see, this is a little bit more flexible than an if statement.
It's actually preferred in a variety of cases when you're developing in JavaScript to use which case
instead of using NFLs, and you can certainly use it AFL's and where you could use the ternary operator
and you could nest ternary operations and nest if else statements.
To get where you need to go and to do a very similar logic, but in which case definitely simplifies
some situations where you want to have a similar format in many cases and different formats in other
cases.
So there you go.
And then obviously you can get switch case structures that are much more complex than this.
But this is a great example to get started.
All right.
That's it for Section four.
We're going to move on to our code challenge in the next video.