1 00:00:00,770 --> 00:00:01,940 Welcome back everybody. 2 00:00:01,940 --> 00:00:02,750 All right. 3 00:00:02,750 --> 00:00:09,110 So let's go ahead and let's go and add something to the if statement so if I type in any kind of word 4 00:00:09,110 --> 00:00:13,590 here and I change the text it all works just same as the last of Toral. 5 00:00:13,610 --> 00:00:18,550 Now you can add something to the statement called an L statement which is something you just say. 6 00:00:18,550 --> 00:00:18,920 Else. 7 00:00:18,920 --> 00:00:21,690 Now of course an else statement needs to curly braces. 8 00:00:21,830 --> 00:00:27,800 And what I mean to do here is I'm going to copy this over and paste it in here instead of making change 9 00:00:27,800 --> 00:00:29,840 text variable to something. 10 00:00:29,840 --> 00:00:37,390 I'm just going to make it make two strings saying else statement fired up like that k and all it's all 11 00:00:37,560 --> 00:00:44,450 going to say is that when I do this here for example if I type in word f here it's going to work because 12 00:00:44,810 --> 00:00:46,060 cool numbers equal one. 13 00:00:46,160 --> 00:00:50,960 But if I change just two instead of the if statement is going to go to the else and let's just walk 14 00:00:50,960 --> 00:00:51,220 through. 15 00:00:51,230 --> 00:00:55,840 So is if the if statement is equal to 1 then this is going to work. 16 00:00:56,090 --> 00:01:02,810 Elle's means that if cool number is equal to any other number other than 1 it will go ahead and put 17 00:01:02,810 --> 00:01:07,880 this in here so I can type in whatever I want but it's going to say L statement as far as always going 18 00:01:07,880 --> 00:01:13,310 to say that if cool number is not equal to what it could be equal to a thousand it can be equal to negative 19 00:01:13,310 --> 00:01:14,170 56. 20 00:01:14,180 --> 00:01:18,350 It doesn't matter what what cool number is equal to if it's not equal to 1. 21 00:01:18,410 --> 00:01:20,140 The statements get to fire. 22 00:01:20,180 --> 00:01:27,050 Now the other thing that we need to check up here is that you'll see that there are two change text 23 00:01:27,170 --> 00:01:28,070 variables. 24 00:01:28,220 --> 00:01:31,310 And why is why can this work. 25 00:01:31,340 --> 00:01:36,170 So you'll see that there is a change text variable here and then a change takes a variable here. 26 00:01:36,200 --> 00:01:42,200 Now in a couple of previous tutorials I did tell you that you can't make a variable equal to the same 27 00:01:42,200 --> 00:01:42,660 name. 28 00:01:42,830 --> 00:01:46,620 And I did say that but it changes a little bit here. 29 00:01:46,690 --> 00:01:52,700 If I were to add a number another variable called Cool number it would throw an exception because the 30 00:01:52,700 --> 00:01:56,110 computer doesn't necessarily know which cue which variable to look at. 31 00:01:56,120 --> 00:01:59,920 So it could be cool number or cool number which is the same. 32 00:01:59,920 --> 00:02:01,310 It gets confused. 33 00:02:01,460 --> 00:02:08,180 However when you set up a variable within these curly brackets this this works is something called variable 34 00:02:08,180 --> 00:02:15,220 scope meaning that change takes variable is only usable within this if statement. 35 00:02:15,260 --> 00:02:19,320 I can't use it outside of this if statement at all. 36 00:02:19,340 --> 00:02:19,870 Right. 37 00:02:19,970 --> 00:02:26,620 And again just change text variable is only usable within the else statement. 38 00:02:26,830 --> 00:02:28,390 It's not usable outside that. 39 00:02:28,390 --> 00:02:34,280 So if I Hopoate outside the IF and then by the way this is the entire If statement here. 40 00:02:34,430 --> 00:02:39,550 This is the if statement and this is the statement but the whole thing works like this. 41 00:02:39,590 --> 00:02:40,210 OK. 42 00:02:40,370 --> 00:02:41,590 And. 43 00:02:41,960 --> 00:02:48,110 And so if you think about it here this is more function we can you know do some stuff in here but if 44 00:02:48,110 --> 00:02:57,380 I type in change text variable k you see that it does kind of work but it won't it won't. 45 00:02:57,380 --> 00:03:01,110 You can see that there's a whole bunch of warnings here that the text changes. 46 00:03:01,220 --> 00:03:08,840 But again you know in this editor it doesn't it only looks for the strings within within the document 47 00:03:08,860 --> 00:03:10,670 and doesn't look for it inside scope. 48 00:03:10,670 --> 00:03:13,820 You need to go to something like Visual Studio or next quarter of stuff like that. 49 00:03:13,840 --> 00:03:14,340 OK. 50 00:03:14,390 --> 00:03:19,730 But you can see there's four warnings here and because this variable is essentially undefined meaning 51 00:03:19,730 --> 00:03:22,190 that it doesn't even know it exists right. 52 00:03:22,220 --> 00:03:26,300 And again remember you have to declare the variable which is what I've done here. 53 00:03:26,300 --> 00:03:31,130 In order for the computer to see if that variable is actually usable. 54 00:03:31,130 --> 00:03:38,210 So again I can get away with this and we can I can get away with actually having to change text variable 55 00:03:38,900 --> 00:03:44,490 in as many if statements is what I could have a 100 of these if I really wanted to. 56 00:03:44,660 --> 00:03:52,300 Now the major question is is should you change the variable within the if any else statement. 57 00:03:52,490 --> 00:03:58,580 So for example here you can see that it says there's two changes text variables that can get kind of 58 00:03:58,580 --> 00:03:59,700 confusing. 59 00:03:59,750 --> 00:04:01,440 Some people do change it up. 60 00:04:01,610 --> 00:04:04,500 It's up to you whether you want to do that or not. 61 00:04:04,520 --> 00:04:09,500 Personally I tend to not use these local variables as much as I can. 62 00:04:09,500 --> 00:04:15,350 One thing that javascript is actually really good at is referencing virtual variables across scope in 63 00:04:15,350 --> 00:04:16,670 other programming languages. 64 00:04:16,670 --> 00:04:19,380 It's not necessarily that easy. 65 00:04:19,400 --> 00:04:23,180 All right so for the most part that is how an else statement works. 66 00:04:23,180 --> 00:04:25,500 All right I'll see you guys in next tutorial.