WEBVTT

00:01.450 --> 00:06.130
When you write the code almost every time you want to perform different actions for different decisions,

00:06.580 --> 00:10.030
for that we frequently use conditional statement in our code.

00:11.380 --> 00:17.050
Generally, a conditional statement is the part of decision making in JavaScript, the conditional statement

00:17.050 --> 00:22.600
is a statement that will evaluate condition to be either true or false.

00:23.500 --> 00:29.470
As your JavaScript programs get more sophisticated, you will need to make use of conditional statements

00:29.890 --> 00:32.080
that allow your program to make decisions.

00:32.930 --> 00:37.710
Nearly all other programming languages use conditionals, and JavaScript is no exception.

00:38.770 --> 00:43.840
What do we want the block of code to be executed if a specified condition is true or false?

00:44.290 --> 00:50.230
We use if our statement if you take a look on the screen, you will see the general structure of if

00:50.230 --> 00:57.160
statement it starts with if keywords, which is followed by the condition inside the Brace's, the condition

00:57.160 --> 00:58.240
which should be checked.

00:58.240 --> 01:04.900
If it is true or false, then we have the block of code inside the collaborator's and it's executed.

01:04.900 --> 01:10.240
If the condition is true, if it's false, then the code inside the statement will run.

01:10.930 --> 01:18.130
All right, let's go to Brackett's and create the variables my child equals to Alexis.

01:19.660 --> 01:22.420
And then variable gender equals.

01:23.940 --> 01:24.450
To me.

01:27.210 --> 01:31.300
Now, let's use F.L. statements and check the following condition.

01:32.430 --> 01:36.330
So if gender three equals to male.

01:38.540 --> 01:40.980
Then run in council.

01:43.170 --> 01:47.460
My child plus is my son.

01:50.840 --> 01:58.190
And if the condition is false, then in a statement, again, running Castle, my child.

02:00.300 --> 02:02.130
Plus is my daughter.

02:04.800 --> 02:10.440
So in this statement, we have the condition gender triple equal to male, and we need to check if it's

02:10.440 --> 02:15.540
true or false, Alexis can be denied either for male or for female.

02:15.930 --> 02:18.820
And we wonder how the parents should call him or her.

02:19.650 --> 02:21.830
So you see that condition inside the boys.

02:21.850 --> 02:22.470
Is it true?

02:22.470 --> 02:25.360
And therefore, the code in its statement is executed.

02:25.860 --> 02:27.600
We got Alexis is my son.

02:28.470 --> 02:37.380
If we change the gender and write the value as female, then the condition will be false and the block

02:37.380 --> 02:43.370
of code inside each statement will be skipped and the code inside the statement will be executed.

02:44.130 --> 02:46.500
So we have Alexis is my daughter.

02:47.670 --> 02:53.790
If we want to execute code based only on the conditions, true value, then it's not necessary to use

02:53.790 --> 02:57.920
our statement just using if statement is absolutely enough.

02:58.740 --> 03:00.450
So let's get rid of our statement.

03:02.250 --> 03:07.650
You said that the condition is false because of the female value and therefore we don't have result

03:07.650 --> 03:17.220
in council, the block of code inside if escaped, if we change female into male, then we will get

03:17.850 --> 03:18.740
the same result.

03:19.380 --> 03:21.210
Alexis is my son.

03:22.320 --> 03:27.810
Before we finish, I would like to show you something that is very helpful and frequently used, especially

03:27.810 --> 03:31.340
when you deal with a bunch of lines of code, I'm talking about the comments.

03:32.100 --> 03:36.500
They are very useful when you want to either describe the code or post the code.

03:37.020 --> 03:42.800
We have two types of comments, single line and multiline, in order to write a single line comment

03:42.810 --> 03:44.670
we need to use for slashes.

03:45.300 --> 03:50.300
And that the comment you can see that color of code is great.

03:50.730 --> 03:57.120
The text editor makes it different from other working codes and also in JavaScript, Engine says slashes

03:57.630 --> 04:01.800
it understands that this code is commented out and it doesn't executed.

04:02.790 --> 04:06.510
In order to comment multiple lines of code, we can use multiline commenting.

04:06.840 --> 04:12.750
We need to write, slash and start at the beginning of the code and start and slash at the end of the

04:12.750 --> 04:13.100
code.

04:13.920 --> 04:16.520
So you see that whole code is great.

04:17.490 --> 04:21.390
Reload the page and you see that the code is not executed.

04:23.400 --> 04:24.000
All right.

04:24.750 --> 04:29.010
In this lecture, we have talked about conditional statements and commenting.

04:29.190 --> 04:30.060
Let's stop here.

04:30.210 --> 04:31.410
See you in the next video.
