1
00:00:00,690 --> 00:00:05,670
This section is all about conditional statement.

2
00:00:06,360 --> 00:00:11,520
Conditional statement is also known as making decision.

3
00:00:12,180 --> 00:00:14,310
So what is a conditional statement?

4
00:00:15,390 --> 00:00:25,530
Conditional statements are statements or set of commands that will only be executed if a specified condition

5
00:00:25,530 --> 00:00:26,400
is met.

6
00:00:27,000 --> 00:00:33,630
This is crucial part when it comes to programming, because programming is all about making decisions

7
00:00:33,630 --> 00:00:34,530
with code.

8
00:00:35,310 --> 00:00:43,500
A practical example is let's say that we have an application and for the application, if you haven't,

9
00:00:43,500 --> 00:00:48,720
log in, we will not allow you to use the application.

10
00:00:48,990 --> 00:00:56,280
On the other hand, if you haven't pay your subscription for our services, you'll be allowed to use

11
00:00:56,280 --> 00:00:57,420
the application.

12
00:00:57,810 --> 00:01:06,840
Or let's take YouTube, for example, before you be put on the monetization program unless you have

13
00:01:06,840 --> 00:01:09,300
some number of subscribers.

14
00:01:09,570 --> 00:01:18,420
So if your subscriber is less than a certain number, then you'll be allowed to use the monetization

15
00:01:18,420 --> 00:01:19,080
program.

16
00:01:19,110 --> 00:01:26,100
So the conditional statement depends on the programmer and how you want your application to behave.

17
00:01:26,130 --> 00:01:29,010
That's where you need conditional statement.

18
00:01:29,220 --> 00:01:36,390
So now that we've learned what is called logical operators variables, now let's combine all these together

19
00:01:36,390 --> 00:01:38,520
to write real code.

20
00:01:39,030 --> 00:01:43,920
So let's get back to visual seed code and get started with conditional statement.

21
00:01:45,070 --> 00:01:55,600
Well, as usual, I have created a new folder and have named it as conditionals or conditionals, so

22
00:01:55,600 --> 00:01:58,040
you can name it whatever you want.

23
00:01:58,060 --> 00:01:59,270
As you can see here.

24
00:01:59,290 --> 00:02:01,570
That's how I name it as conditionals.

25
00:02:01,900 --> 00:02:10,419
And in there I have my index dot a HTML file, and then I have my script file where we are going to

26
00:02:10,419 --> 00:02:11,950
write our JavaScript.

27
00:02:12,130 --> 00:02:17,390
So inside the HTML, I have connected my JavaScript.

28
00:02:17,410 --> 00:02:20,590
So let's go ahead and write our.

29
00:02:22,340 --> 00:02:25,040
JavaScript could perfect.

30
00:02:25,190 --> 00:02:27,740
So here comes.

31
00:02:27,920 --> 00:02:29,630
How can we write?

32
00:02:30,580 --> 00:02:33,190
A code that makes decision.

33
00:02:33,760 --> 00:02:39,250
So let me have a nice comment and call this one.

34
00:02:40,870 --> 00:02:42,550
Conditional statement.

35
00:02:42,550 --> 00:02:45,400
Conditional statement.

36
00:02:47,700 --> 00:02:48,570
Perfect.

37
00:02:49,070 --> 00:02:49,640
Okay.

38
00:02:49,650 --> 00:02:56,460
So how can we write a conditional statement where we use a key word called if?

39
00:02:56,820 --> 00:02:58,020
As soon as I type.

40
00:02:58,050 --> 00:03:05,430
If the usage code has given me those IntelliSense, then you bring in your bracket and then your carry

41
00:03:05,430 --> 00:03:06,210
braces.

42
00:03:06,420 --> 00:03:09,300
So let me expand my carry braces here.

43
00:03:09,330 --> 00:03:14,640
So inside my bracket here is where we call condition.

44
00:03:15,150 --> 00:03:17,760
This is just some placeholder condition.

45
00:03:17,760 --> 00:03:26,430
So my condition goes inside my bracket and then the code to run is to be here.

46
00:03:26,430 --> 00:03:28,920
Let's say code to run.

47
00:03:29,400 --> 00:03:34,740
This code will run if and only my condition is true.

48
00:03:35,220 --> 00:03:36,810
Bear in mind about this.

49
00:03:37,140 --> 00:03:45,500
If your condition is true, then your code inside this scope or carry basis is going to run.

50
00:03:45,510 --> 00:03:53,730
And remember, we've talk about logical operators comprising operators, assignment operators, arithmetic

51
00:03:53,730 --> 00:03:54,440
operators.

52
00:03:54,450 --> 00:04:00,210
We are going to combine all these together to write logical or conditional statement.

53
00:04:00,450 --> 00:04:03,840
So now we know a statement which is true, right?

54
00:04:03,840 --> 00:04:08,600
So we will talk about foresee and true values in the next video.

55
00:04:08,610 --> 00:04:14,230
For now, let's ignore about that and let's have some statement that is going to return, true or false?

56
00:04:14,250 --> 00:04:14,850
All right.

57
00:04:14,850 --> 00:04:18,300
Let's write some code to explain this logic.

58
00:04:18,660 --> 00:04:18,990
All right.

59
00:04:18,990 --> 00:04:26,250
So what we want to implement is that let's say that we are going to watch movie.

60
00:04:26,370 --> 00:04:34,860
But before you can enter and watch the movie, unless your age is above 18 years.

61
00:04:34,860 --> 00:04:42,630
So 18 years is the minimum age that you need to have before you can watch the movie or go and watch

62
00:04:42,630 --> 00:04:49,290
the movie so we can declare a variable called age, which is equal to 18 years.

63
00:04:49,830 --> 00:04:53,970
That is the the benchmark or for the age.

64
00:04:54,210 --> 00:04:58,730
So here we are going to write some of statement.

65
00:04:58,740 --> 00:05:01,470
So let's comment out this the syntax.

66
00:05:01,620 --> 00:05:03,750
And now let me come up down here.

67
00:05:03,900 --> 00:05:07,640
I think I can bring this one here so that bring this one up here.

68
00:05:07,740 --> 00:05:08,250
Yes.

69
00:05:09,090 --> 00:05:09,880
Yes, this.

70
00:05:09,900 --> 00:05:10,410
Good.

71
00:05:10,500 --> 00:05:18,360
So here we are going to check if the age that the user is trying to provide, is it less than or more

72
00:05:18,360 --> 00:05:20,970
than the benchmark age, which is 18 years?

73
00:05:21,510 --> 00:05:22,350
Let's write the code.

74
00:05:22,350 --> 00:05:23,280
So if.

75
00:05:24,970 --> 00:05:29,110
The age that I want to provide now I want to set up my run.

76
00:05:29,110 --> 00:05:40,810
My age is 20 years is the age that I'm providing is it's more than or equal to let's say it's more than

77
00:05:40,810 --> 00:05:43,150
the age that the movie.

78
00:05:44,060 --> 00:05:49,880
Is required us to have known if this condition is true.

79
00:05:50,060 --> 00:05:54,590
The code that we are going to write here is going to run for now.

80
00:05:54,590 --> 00:05:57,740
We are going to dump the result into the console.

81
00:05:58,070 --> 00:06:02,960
So if that's the case, then we can console.log something.

82
00:06:02,960 --> 00:06:03,950
And since that.

83
00:06:05,200 --> 00:06:06,040
Yes.

84
00:06:06,980 --> 00:06:08,900
You qualify?

85
00:06:11,540 --> 00:06:14,870
To watch their movies.

86
00:06:16,270 --> 00:06:17,010
Yes.

87
00:06:17,020 --> 00:06:19,840
So if I save it now, let's check the console.

88
00:06:19,870 --> 00:06:21,340
Now you know how to open a console.

89
00:06:21,340 --> 00:06:23,950
Right click inspect or on a keyboard.

90
00:06:23,980 --> 00:06:28,070
Just press option command I and you're good to go.

91
00:06:28,090 --> 00:06:29,140
That's or Mark.

92
00:06:29,140 --> 00:06:30,700
I don't know what about for the windows?

93
00:06:30,970 --> 00:06:32,320
We see that now.

94
00:06:32,350 --> 00:06:33,970
The code has run.

95
00:06:33,970 --> 00:06:34,960
I see.

96
00:06:34,990 --> 00:06:35,980
Yes.

97
00:06:36,910 --> 00:06:39,700
You qualify to watch the movies?

98
00:06:39,790 --> 00:06:41,440
That is my age.

99
00:06:41,650 --> 00:06:47,830
That is a result because my age here I provide it is more than 18 years.

100
00:06:47,830 --> 00:06:49,810
So my code here is true.

101
00:06:49,840 --> 00:06:52,060
That's why I have this result.

102
00:06:52,090 --> 00:06:54,310
You qualify to watch the movie.

103
00:06:54,430 --> 00:06:56,770
That is if statement.

104
00:06:57,160 --> 00:07:06,280
So what about if I provide my age, which is, let's say, 15 years?

105
00:07:06,310 --> 00:07:10,210
You see, when I save it, there is no resort here.

106
00:07:10,540 --> 00:07:19,690
So how can we also display something that maybe your age is below 18 years, so please go home.

107
00:07:19,810 --> 00:07:21,730
How can we do that?

108
00:07:22,060 --> 00:07:25,500
All right, so let's see what we can do to handle that one.

109
00:07:25,510 --> 00:07:28,780
If your age is less than 18 years, the next video.

