1
00:00:00,630 --> 00:00:02,120
Hello and welcome.

2
00:00:02,220 --> 00:00:13,590
In this video I'll be introducing you to conditionals condition was r chord structures which allow you

3
00:00:14,070 --> 00:00:27,600
to test if an expression or a condition returns true or not they are used to perform different actions

4
00:00:28,050 --> 00:00:31,980
based on different conditions.

5
00:00:32,070 --> 00:00:43,710
The common conditional statements are an if statement basically in an if statement is used to specify

6
00:00:43,800 --> 00:00:52,320
a block of code that will be executed if a specified condition is true.

7
00:00:52,350 --> 00:01:04,260
We also have an else statement basically that checks if the condition that is set within the if statement

8
00:01:04,980 --> 00:01:06,680
is true or false.

9
00:01:06,690 --> 00:01:14,240
If that is false then the code inside the else block will execute.

10
00:01:14,670 --> 00:01:23,280
So the L statement will only come into effect if the condition set within the if statement returns false.

11
00:01:24,210 --> 00:01:31,860
So in my console I have caught a variable here that I defined called my number and I've given it a value

12
00:01:31,860 --> 00:01:40,770
of 7 and I'm using an if statement which is a conditional statement to test a condition.

13
00:01:40,950 --> 00:01:50,610
So I'm checking if the variable called my name is equal to 7.

14
00:01:51,270 --> 00:02:00,780
If it is the code this code here will be executed which is console the log basically means it will print

15
00:02:00,780 --> 00:02:02,130
out this message.

16
00:02:02,130 --> 00:02:09,180
Inside this console it will say Lucky 7 if the condition is true but looking at the condition this condition

17
00:02:09,180 --> 00:02:15,330
is definitely true because a variable has a value of 7 and just check in here.

18
00:02:15,330 --> 00:02:21,570
This is the condition the expression inside the F which is this.

19
00:02:21,570 --> 00:02:23,920
Here is the test.

20
00:02:23,920 --> 00:02:34,170
Okay so this uses the identity operator which is as equals to here to compare the value to compare if

21
00:02:34,170 --> 00:02:41,520
this value here is 7 if is equal to 7 if it is it will print out that.

22
00:02:41,520 --> 00:02:45,330
So I'm just going to press enter and it will print out.

23
00:02:45,340 --> 00:02:47,310
Lock is 7 in the console.

24
00:02:47,580 --> 00:02:50,550
So in this case the condition is true.

25
00:02:50,730 --> 00:02:54,810
So no other code needs to be executed.

26
00:02:54,810 --> 00:03:03,870
However you can also create a condition in which you add an else statement so that if the condition

27
00:03:04,410 --> 00:03:13,290
inside the if statement is wrong then a different block of code will execute which is located inside

28
00:03:13,500 --> 00:03:15,240
the else block.

29
00:03:16,480 --> 00:03:18,440
So here I've got another variable.

30
00:03:18,490 --> 00:03:19,870
Same called my number.

31
00:03:19,870 --> 00:03:27,000
I've changed the value to 10 and here I've included two statements.

32
00:03:27,010 --> 00:03:29,920
The if statement and the L statement.

33
00:03:29,980 --> 00:03:34,120
So what happens is the comparison is made.

34
00:03:34,120 --> 00:03:40,570
The condition is tested and the test is inside the if block inside here.

35
00:03:40,570 --> 00:03:42,820
So is testing if this variable.

36
00:03:42,820 --> 00:03:45,500
My number is equal to 7.

37
00:03:45,520 --> 00:03:49,370
This will return false because the value is 10.

38
00:03:49,480 --> 00:03:55,410
So what I have on this block of code here that says Lock is 7 will not run.

39
00:03:55,420 --> 00:04:00,570
So it will not get executed because the value is wrong.

40
00:04:00,610 --> 00:04:01,810
So what happens.

41
00:04:01,810 --> 00:04:09,950
It will skip this block and need to execute this code because this condition inside the F is wrong.

42
00:04:09,970 --> 00:04:12,550
It doesn't evaluate to.

43
00:04:12,670 --> 00:04:20,200
So once a comparison has been made it all wrong the code that matches the comparison.

44
00:04:20,210 --> 00:04:26,190
So in this case the code inside the comparison is made inside the F block.

45
00:04:26,560 --> 00:04:33,730
So it tested the condition the condition tested false because the values 7 is not the cause of 7.

46
00:04:33,910 --> 00:04:35,570
So it's not close to 10.

47
00:04:35,590 --> 00:04:39,870
So the block of code here that says lock in 7 will not run.

48
00:04:39,880 --> 00:04:47,020
Instead it will run this inside the console anyway you see console don't log means it's going to print

49
00:04:47,110 --> 00:04:51,410
a message inside the console so 5 press enter.

50
00:04:51,550 --> 00:04:59,350
He can see you saying you're not very lucky today because this condition that we tested did not evaluate

51
00:04:59,410 --> 00:05:00,010
to true.

52
00:05:00,460 --> 00:05:03,900
So this code here is executed instead.

53
00:05:04,150 --> 00:05:13,020
So in a very simple example here to illustrate how the conditional statement works so there are order

54
00:05:13,030 --> 00:05:19,180
types or conditional statement but the very basic is the F and the FS statement.

55
00:05:19,450 --> 00:05:27,160
So the key thing to note here using the f an L statement is the condition to be tested or the expression

56
00:05:27,160 --> 00:05:31,180
to be tested is always located in the F block.

57
00:05:31,570 --> 00:05:33,700
So that's where you set the condition.

58
00:05:33,700 --> 00:05:36,020
You can see he have set the condition here.

59
00:05:36,280 --> 00:05:43,060
So if that condition does not evaluate to be true then the block of code inside the if statement is

60
00:05:43,060 --> 00:05:47,600
skipped and the one in the else block is executed.

61
00:05:47,650 --> 00:05:54,190
So in between the curly braces see opening curly braces and that's the closing collaborators is where

62
00:05:54,190 --> 00:05:57,340
you write the block of code that will execute.

63
00:05:57,340 --> 00:06:05,220
You can see here this is the block for the F and in the L phone you got the opening curly braces and

64
00:06:05,260 --> 00:06:12,850
the closing curly braces and in between who you call the code block that executes if a condition within

65
00:06:12,850 --> 00:06:16,990
the if statement or the F block is wrong.

66
00:06:17,590 --> 00:06:18,520
So that's it.

67
00:06:18,520 --> 00:06:19,620
I hope it makes sense.

68
00:06:19,630 --> 00:06:21,670
If not please let me know.

69
00:06:21,910 --> 00:06:23,530
Thank you and bye for now.
