Sometimes we need to make correct decision out of several conditions.
This is the case when we need to use an advanced form of Ethan's statement, and it's called if Alcivar
statement.
There is nothing special about this code.
It's just a series of if statements to code, an elusive conditional you call the keywords Al Swift,
followed by a condition in parentheses and a block of code inside Colibri.
If the condition is true, it's block of code will be executed and any remaining codes in the statement
will be skipped over.
This will continue until one of the elusive conditions is true or they all are false.
You can write multiple Elsom statements as much as you want, but LTH should be definitely only one.
So, again, if this condition is true, then the block of code inside the collaborators prices will
be run and all the other statements will be kept.
All right, let's create variable call it prof as a profession and assign to its Disvalue instructor.
Imagine that we want to get the relevant descriptions for the multiple professions.
For that, we need to use several conditions.
But if.
Profession triple equal to instructor.
Then.
Run in Castle.
Profession plus.
Teaches students.
Danus, Alsup statement with a condition if profession triple equals to Dr..
Then.
Right, canceled look profession.
Plus treats people.
Then again, use another elusive statement with a condition if professional triple equals to composer.
And run again in Castle Profession plus creates the music.
And finally, right el statement.
And running kosal professions.
Do not match.
All right, let's run this code so we have instructor teaching students that's because first condition
is true.
Now change the value of instructor into Dr..
Then reload the page and we have a through its people, the result is the same in this case, first
elusive condition is true and that's why we have got this results.
Let's change the condition in second statement.
And instead of composer, write the same value.
Doctor, you said that the both conditions in Alcivar statements are true.
You may expect to get both results in council.
Let's see what happens.
Still, we have the results from the first out of statement.
That's because, as we already said, one of the engine finds true condition.
Then it terminates executing of the remaining statements.
All right.
Now change once again the value of profession into, let's say, engineer reloader page.
And you see that professions do not match.
It means that all the conditions are false and also statement is executed, as we said.
Remember that we can use it all at once.
All right, in order to check multiple conditions simultaneously in JavaScript, we can use another
type of apparatus which is called logical.
Logical operators are used to determine the logic between variables or values.
We have three types of logical operators, logical and which is expressed with two ampersands logical
or which is written by double vertical bars and logical not, which is an exclamation mark.
Let's consider how each of these operators work for demonstrating that I'm going to use eval statements
as we set the logical operators, allow us to compare multiple conditions.
So when we use an operator with two conditions, then both of them have to be true in order to be the
whole expression to write if that five triple equal to five user and operator.
And then the second condition for.
Triple EcoStar for.
Then, if this condition is true, run in council.
Condition is true.
And if it's false.
Then use our statement and run in causal condition is false.
Reload the page and you see the condition is true.
The reason is that five triple equals five is true and false report equals four is true as well.
Therefore, the whole condition is true.
Because of that, the component operators have higher precedence than logical operators, the engine
at first compares the numbers and after that it checks if the condition is true or false for logical
and operator.
If we make one of the conditions false, for example, five triple equals to four, then the whole condition
will be false and we will get condition is false in Castle.
All right.
The difference between logical and and logical are is that if one of the condition is true, that the
whole condition is still true for logical or operator, so you see that the condition on the left side
is false, but the condition on the right side is true.
And that's why we got condition is true in Castle.
Logical operator gives us false value when both conditions are false, so right for triple equals to
three.
Now both sides are false and therefore the whole condition is false.
OK, the last logical operator not gives us always an opposite value.
If the condition is true, then it returns false.
So if we write here not true, we will get condition is false.
All right, so let's briefly describe the logical operators that we have just discussed, logical and
gives us true value when both conditions are true, if one of them or both of them are false, that
it gives us false.
Logical or gives us true value if both conditions are true or one of them is true, if both conditions
are false, then it gives us false.
As for logical not, it gives us opposite values, if the condition is true, it gives us false and
vice versa.
OK, in this lecture, we have discussed Alsup statement and logical operators.
Now it's time to practice and the coming videos, the coding task and a little quiz are waiting for
you.
So let's go ahead.