WEBVTT

00:01.850 --> 00:05.610
Sometimes we need to make correct decision out of several conditions.

00:05.990 --> 00:11.810
This is the case when we need to use an advanced form of Ethan's statement, and it's called if Alcivar

00:11.810 --> 00:12.320
statement.

00:13.240 --> 00:14.960
There is nothing special about this code.

00:14.980 --> 00:21.460
It's just a series of if statements to code, an elusive conditional you call the keywords Al Swift,

00:21.940 --> 00:26.710
followed by a condition in parentheses and a block of code inside Colibri.

00:27.670 --> 00:33.730
If the condition is true, it's block of code will be executed and any remaining codes in the statement

00:33.730 --> 00:34.720
will be skipped over.

00:35.020 --> 00:40.210
This will continue until one of the elusive conditions is true or they all are false.

00:41.370 --> 00:47.610
You can write multiple Elsom statements as much as you want, but LTH should be definitely only one.

00:48.540 --> 00:53.760
So, again, if this condition is true, then the block of code inside the collaborators prices will

00:53.760 --> 00:57.060
be run and all the other statements will be kept.

00:58.390 --> 01:07.430
All right, let's create variable call it prof as a profession and assign to its Disvalue instructor.

01:08.230 --> 01:12.150
Imagine that we want to get the relevant descriptions for the multiple professions.

01:12.820 --> 01:15.370
For that, we need to use several conditions.

01:15.730 --> 01:16.330
But if.

01:17.180 --> 01:20.510
Profession triple equal to instructor.

01:22.660 --> 01:23.080
Then.

01:24.160 --> 01:25.150
Run in Castle.

01:26.770 --> 01:27.790
Profession plus.

01:29.260 --> 01:30.790
Teaches students.

01:34.040 --> 01:40.940
Danus, Alsup statement with a condition if profession triple equals to Dr..

01:43.970 --> 01:44.360
Then.

01:46.130 --> 01:48.080
Right, canceled look profession.

01:49.530 --> 01:51.630
Plus treats people.

01:54.400 --> 02:02.260
Then again, use another elusive statement with a condition if professional triple equals to composer.

02:05.380 --> 02:10.990
And run again in Castle Profession plus creates the music.

02:14.970 --> 02:18.390
And finally, right el statement.

02:20.380 --> 02:22.600
And running kosal professions.

02:24.240 --> 02:25.170
Do not match.

02:27.260 --> 02:35.150
All right, let's run this code so we have instructor teaching students that's because first condition

02:35.150 --> 02:35.630
is true.

02:36.990 --> 02:40.920
Now change the value of instructor into Dr..

02:43.040 --> 02:50.900
Then reload the page and we have a through its people, the result is the same in this case, first

02:50.900 --> 02:54.120
elusive condition is true and that's why we have got this results.

02:55.100 --> 02:57.800
Let's change the condition in second statement.

02:57.800 --> 03:01.560
And instead of composer, write the same value.

03:01.700 --> 03:06.160
Doctor, you said that the both conditions in Alcivar statements are true.

03:06.860 --> 03:09.320
You may expect to get both results in council.

03:10.070 --> 03:11.030
Let's see what happens.

03:11.930 --> 03:15.040
Still, we have the results from the first out of statement.

03:15.620 --> 03:19.910
That's because, as we already said, one of the engine finds true condition.

03:20.480 --> 03:23.740
Then it terminates executing of the remaining statements.

03:24.920 --> 03:25.400
All right.

03:25.940 --> 03:33.830
Now change once again the value of profession into, let's say, engineer reloader page.

03:34.840 --> 03:37.120
And you see that professions do not match.

03:37.660 --> 03:43.900
It means that all the conditions are false and also statement is executed, as we said.

03:44.260 --> 03:46.660
Remember that we can use it all at once.

03:48.150 --> 03:54.000
All right, in order to check multiple conditions simultaneously in JavaScript, we can use another

03:54.000 --> 03:56.880
type of apparatus which is called logical.

03:57.510 --> 04:01.600
Logical operators are used to determine the logic between variables or values.

04:02.340 --> 04:09.990
We have three types of logical operators, logical and which is expressed with two ampersands logical

04:09.990 --> 04:16.530
or which is written by double vertical bars and logical not, which is an exclamation mark.

04:17.460 --> 04:24.750
Let's consider how each of these operators work for demonstrating that I'm going to use eval statements

04:25.350 --> 04:29.750
as we set the logical operators, allow us to compare multiple conditions.

04:30.300 --> 04:36.720
So when we use an operator with two conditions, then both of them have to be true in order to be the

04:36.720 --> 04:46.500
whole expression to write if that five triple equal to five user and operator.

04:47.370 --> 04:50.400
And then the second condition for.

04:51.540 --> 04:52.680
Triple EcoStar for.

04:54.320 --> 04:57.620
Then, if this condition is true, run in council.

04:58.580 --> 05:00.020
Condition is true.

05:04.250 --> 05:05.780
And if it's false.

05:07.230 --> 05:13.820
Then use our statement and run in causal condition is false.

05:16.590 --> 05:20.110
Reload the page and you see the condition is true.

05:20.640 --> 05:26.170
The reason is that five triple equals five is true and false report equals four is true as well.

05:26.580 --> 05:28.520
Therefore, the whole condition is true.

05:29.610 --> 05:36.060
Because of that, the component operators have higher precedence than logical operators, the engine

05:36.240 --> 05:42.600
at first compares the numbers and after that it checks if the condition is true or false for logical

05:42.600 --> 05:43.470
and operator.

05:44.800 --> 05:53.620
If we make one of the conditions false, for example, five triple equals to four, then the whole condition

05:53.620 --> 05:57.040
will be false and we will get condition is false in Castle.

05:58.030 --> 05:58.480
All right.

06:00.340 --> 06:06.310
The difference between logical and and logical are is that if one of the condition is true, that the

06:06.310 --> 06:13.060
whole condition is still true for logical or operator, so you see that the condition on the left side

06:13.060 --> 06:16.350
is false, but the condition on the right side is true.

06:16.780 --> 06:19.420
And that's why we got condition is true in Castle.

06:20.950 --> 06:28.330
Logical operator gives us false value when both conditions are false, so right for triple equals to

06:28.330 --> 06:28.700
three.

06:29.560 --> 06:33.820
Now both sides are false and therefore the whole condition is false.

06:35.420 --> 06:41.110
OK, the last logical operator not gives us always an opposite value.

06:41.590 --> 06:44.120
If the condition is true, then it returns false.

06:44.170 --> 06:51.310
So if we write here not true, we will get condition is false.

06:52.690 --> 06:59.170
All right, so let's briefly describe the logical operators that we have just discussed, logical and

06:59.170 --> 07:05.170
gives us true value when both conditions are true, if one of them or both of them are false, that

07:05.170 --> 07:06.220
it gives us false.

07:07.490 --> 07:14.870
Logical or gives us true value if both conditions are true or one of them is true, if both conditions

07:14.870 --> 07:16.910
are false, then it gives us false.

07:18.190 --> 07:25.270
As for logical not, it gives us opposite values, if the condition is true, it gives us false and

07:25.390 --> 07:26.250
vice versa.

07:28.030 --> 07:32.830
OK, in this lecture, we have discussed Alsup statement and logical operators.

07:33.370 --> 07:38.800
Now it's time to practice and the coming videos, the coding task and a little quiz are waiting for

07:38.800 --> 07:38.990
you.

07:39.730 --> 07:40.870
So let's go ahead.
