1 00:00:00,790 --> 00:00:01,930 All right welcome back everybody. 2 00:00:01,930 --> 00:00:02,740 I'm just going to go ahead. 3 00:00:02,740 --> 00:00:04,630 I'm going to put this back in here. 4 00:00:04,660 --> 00:00:08,910 It's pretty simple and I'm going to go get rid of that function right here in this a Tauriel. 5 00:00:08,910 --> 00:00:12,050 I want to show you something called an if statement here. 6 00:00:12,130 --> 00:00:12,660 OK. 7 00:00:12,880 --> 00:00:14,370 And an if statement. 8 00:00:14,410 --> 00:00:16,820 All it does is it checks to see if something is true. 9 00:00:16,840 --> 00:00:23,440 So for example if I were to say you know if if you were to imagine your house in the heat if the heat 10 00:00:24,040 --> 00:00:26,070 isn't on then it's going to be cool. 11 00:00:26,110 --> 00:00:32,370 That's what an if statement is though and if the heat is on it's going to be warm so it checks for condition 12 00:00:32,830 --> 00:00:35,410 and it has an action as a result. 13 00:00:35,410 --> 00:00:39,880 So usually you need some kind of variable and obviously set up a global variable and I'll call this 14 00:00:39,880 --> 00:00:48,860 variable we can call this variable number or cool numbers like that. 15 00:00:48,860 --> 00:00:49,340 Right. 16 00:00:49,430 --> 00:00:50,630 And we'll make it equal to 1. 17 00:00:50,650 --> 00:00:52,880 Right so I will initialiser. 18 00:00:53,290 --> 00:00:53,900 All right so we. 19 00:00:53,960 --> 00:00:55,300 So we have a cool number. 20 00:00:55,310 --> 00:01:01,610 Now what I can do here is if I put in an IF statement on his statement looks looks like. 21 00:01:01,610 --> 00:01:02,420 Is this all we got. 22 00:01:02,420 --> 00:01:08,510 If cool number now by the way what I'm about to show you. 23 00:01:08,540 --> 00:01:13,090 I could spend an hour talking about I'm going to put double equals to one. 24 00:01:13,340 --> 00:01:14,130 OK. 25 00:01:14,180 --> 00:01:16,380 And you need it curly bracket again. 26 00:01:16,560 --> 00:01:16,850 OK. 27 00:01:16,850 --> 00:01:19,550 And when you put all this in the curly bracket here. 28 00:01:19,730 --> 00:01:23,730 So if cool number is equal to one then it's going to execute this code. 29 00:01:23,840 --> 00:01:27,710 And if cool number doesn't equal one that it won't execute the code. 30 00:01:27,710 --> 00:01:33,800 So you can imagine that if we type in something here like this fun it still works. 31 00:01:33,800 --> 00:01:34,820 But watch this. 32 00:01:34,850 --> 00:01:40,630 If I change cool number two and I type in fun guess what. 33 00:01:40,640 --> 00:01:45,360 It doesn't work because cool number is not equal to 1. 34 00:01:45,380 --> 00:01:50,050 And so this code doesn't get get executed. 35 00:01:50,270 --> 00:01:56,510 OK so I'm just going to go ahead I'm going to just actually close the H T.M. here and let's just take 36 00:01:56,510 --> 00:01:57,610 a quick look at this. 37 00:01:57,620 --> 00:02:04,850 Now another thing that J has been doesn't necessarily do but pretty much every other programming language 38 00:02:04,850 --> 00:02:08,560 does this is they indent OK and I kind of does this here. 39 00:02:08,570 --> 00:02:13,550 So I'm just going to go ahead I'm going to return this clearly brace just because it it makes a little 40 00:02:13,550 --> 00:02:15,680 bit more sense to look at it like this. 41 00:02:15,680 --> 00:02:21,110 Even though when I program I always put it like this because I know what I'm doing but to explain it 42 00:02:21,140 --> 00:02:22,220 I'm going to go ahead and do this. 43 00:02:22,230 --> 00:02:22,610 OK. 44 00:02:22,820 --> 00:02:29,240 And you'll see that in here you can see that I'm just going to go ahead and Tab this out a bit and you 45 00:02:29,240 --> 00:02:34,070 can see that the curly bridge brackets this clearly bracket looks like this. 46 00:02:34,130 --> 00:02:34,650 OK. 47 00:02:34,880 --> 00:02:39,770 And everything within this function this is what the block of the function is is what my highlighted 48 00:02:39,770 --> 00:02:45,190 text here and everything within the if statement is what I've highlighted here. 49 00:02:45,410 --> 00:02:50,660 So these curly brackets are super important because you need to section off blocks of code because of 50 00:02:50,660 --> 00:02:51,030 it. 51 00:02:51,080 --> 00:02:51,990 And we've already done that. 52 00:02:51,990 --> 00:02:55,700 See that with a function but they also work for if statements k. 53 00:02:55,910 --> 00:03:00,310 Now in some languages what will end up happening is that if you have a one line if statement. 54 00:03:00,320 --> 00:03:09,390 So for example if I just type this and you have you know if cool number equals 1 or equals 2. 55 00:03:09,760 --> 00:03:10,160 OK. 56 00:03:10,160 --> 00:03:13,210 And then we can type in do something like this. 57 00:03:13,430 --> 00:03:20,130 So sometimes you can get away with that but its best practices to always put in the curly brackets. 58 00:03:20,480 --> 00:03:24,100 So you can see that this is the curly brackets here. 59 00:03:24,350 --> 00:03:30,230 And the way it works is that as soon as you open up another curly bracket and you close it the closing 60 00:03:30,230 --> 00:03:34,430 bracket is going to go to the last open curly bracket. 61 00:03:34,430 --> 00:03:38,120 So this is a closing bracket goes up to last open. 62 00:03:38,150 --> 00:03:39,200 Clearly bracket. 63 00:03:39,260 --> 00:03:44,450 This is the last closing bracket is going to go up to the last curly bracket there. 64 00:03:44,450 --> 00:03:44,950 OK. 65 00:03:45,030 --> 00:03:47,230 So cool number is equal to 1. 66 00:03:47,270 --> 00:03:50,840 It's going to do that and we equaled cool number as you will to do. 67 00:03:51,050 --> 00:03:51,570 OK. 68 00:03:51,830 --> 00:03:55,010 Simple enough and let's make sure this works. 69 00:03:55,010 --> 00:03:57,620 One more time I'm just going to type in the word fun. 70 00:03:57,770 --> 00:03:58,810 And there we go. 71 00:03:58,850 --> 00:03:59,700 That's all it is. 72 00:03:59,750 --> 00:04:00,440 OK. 73 00:04:00,440 --> 00:04:02,300 So that is an if statement. 74 00:04:02,320 --> 00:04:04,210 I'll see you guys in next tutorial.