1 00:00:00,180 --> 00:00:05,130 Welcome back, ladies and gentlemen, welcome to new lecture about JavaScript conditionals. 2 00:00:05,250 --> 00:00:12,380 Now, this is a very important lecture in make sure that you understand all of these conditions here. 3 00:00:12,690 --> 00:00:18,180 If you don't just re watch the lecture, because this is the fundamental part of JavaScript. 4 00:00:18,330 --> 00:00:21,900 So we're going to start with if statements, then we're going to go to else. 5 00:00:22,260 --> 00:00:28,680 Then we're going to check what else means switch statements, ternary operator and logical operators. 6 00:00:29,100 --> 00:00:37,050 These means and or and the last one, the exclamation mark means not OK, we don't have time to waste. 7 00:00:37,050 --> 00:00:43,560 We have a lot of things I've created JavaScript lecture for and I'm illington here. 8 00:00:43,740 --> 00:00:45,780 Just do way, not waste time. 9 00:00:46,030 --> 00:00:51,030 OK, so write a comment here that we are going to do. 10 00:00:51,690 --> 00:00:52,410 Let's put it in. 11 00:00:54,890 --> 00:01:01,820 Was working mockable caps, Lock wasn't working for some reason, so JavaScript conditional. 12 00:01:05,390 --> 00:01:16,940 Operators and we're going to say and logical operators very you now make here multiline comment. 13 00:01:19,170 --> 00:01:19,650 Sorry. 14 00:01:20,800 --> 00:01:21,490 And. 15 00:01:22,300 --> 00:01:31,150 Here, what I'm going to right is Java script conditionals, and we're going to I'm going to rewrite 16 00:01:31,150 --> 00:01:32,770 each and every of them if. 17 00:01:35,020 --> 00:01:35,650 Alice. 18 00:01:37,250 --> 00:01:40,320 Or else if switch. 19 00:01:42,810 --> 00:01:47,520 And ternary operator, operator. 20 00:01:47,700 --> 00:01:48,340 Very good. 21 00:01:48,630 --> 00:01:53,160 Now here I will write about logical operators. 22 00:01:58,390 --> 00:02:04,120 Yep, now here we will have and oops, and. 23 00:02:05,250 --> 00:02:14,130 Or they will pop and the last one is not exclamation mark, OK, that is pretty much what we going to 24 00:02:14,130 --> 00:02:15,430 cover in this lecture. 25 00:02:15,450 --> 00:02:17,240 So let's start working on it. 26 00:02:17,550 --> 00:02:19,170 Actually, here we can get rid of. 27 00:02:19,170 --> 00:02:22,180 This doesn't look very nice. 28 00:02:22,200 --> 00:02:25,620 Make sure your coat looks clean and nice. 29 00:02:25,650 --> 00:02:29,600 OK, so that's what we are going to cover in today's lecture. 30 00:02:30,270 --> 00:02:32,480 Let's be clear, a couple of variables here. 31 00:02:32,820 --> 00:02:41,790 Number one, and that will be a variable number two. 32 00:02:42,030 --> 00:02:43,950 And number two, let's put it 30. 33 00:02:45,420 --> 00:02:47,670 And please don't make a space here. 34 00:02:47,970 --> 00:02:54,620 Variable number three, and that will be value of 16. 35 00:02:54,900 --> 00:03:01,440 So we have three variables declared and initialized with initial values no one will hold and number 36 00:03:01,440 --> 00:03:02,920 two will hold 30. 37 00:03:03,090 --> 00:03:05,640 And number three will hold 16. 38 00:03:06,060 --> 00:03:11,490 OK, the first things first we need to explain what if condition means. 39 00:03:11,700 --> 00:03:13,470 So if you say if condition. 40 00:03:16,970 --> 00:03:22,370 Or if statement, it's pretty much the same. 41 00:03:22,520 --> 00:03:25,740 So if statements and conditions means the same thing. 42 00:03:25,760 --> 00:03:30,070 OK, now how we are going to write it if statement. 43 00:03:30,170 --> 00:03:33,740 So the key word is, if so, this is the key word. 44 00:03:33,740 --> 00:03:38,120 We always need to write it like that in inside here. 45 00:03:38,120 --> 00:03:41,300 We need to have these brackets, OK? 46 00:03:41,300 --> 00:03:43,250 Without these brackets, we don't have condition. 47 00:03:43,580 --> 00:03:47,630 So inside these brackets, we are putting the condition in here. 48 00:03:47,640 --> 00:03:55,040 I'm going to say no one is smaller than number two and curly brackets. 49 00:03:55,220 --> 00:04:00,710 So make sure that you are following this this syntax. 50 00:04:00,890 --> 00:04:04,130 So we have if then we have a bracket. 51 00:04:04,130 --> 00:04:04,430 Oops. 52 00:04:05,300 --> 00:04:10,760 And inside those brackets, we do set the condition and now the condition can be anything. 53 00:04:10,760 --> 00:04:14,480 And I just put number one to be smaller then number two. 54 00:04:14,810 --> 00:04:16,730 And that is the true number two. 55 00:04:16,730 --> 00:04:19,640 Sturdee number one is eighty eight. 56 00:04:19,850 --> 00:04:24,740 So here we can just type comes a lot, we can have a block of code here. 57 00:04:24,890 --> 00:04:30,920 We can have anything but just to be very specific and short and to tell you that how if condition is 58 00:04:30,920 --> 00:04:32,570 working, I'm just going to use Konza. 59 00:04:32,840 --> 00:04:35,240 So don't think that only we can write comes a lot. 60 00:04:35,250 --> 00:04:41,280 We can write multiple lines of code here based on our logic and in future you will see just that. 61 00:04:41,570 --> 00:04:48,620 So here I'm going to say number two is bigger than number one. 62 00:04:49,020 --> 00:04:50,840 OK, semicolon there. 63 00:04:52,070 --> 00:04:55,220 And let's go back to our browser. 64 00:04:55,580 --> 00:04:56,270 And here it is. 65 00:04:56,390 --> 00:04:58,460 Number two is bigger than number one. 66 00:04:58,670 --> 00:05:04,280 That is true because we saying if no if this condition is true, then. 67 00:05:05,170 --> 00:05:12,460 This block of code needs to be executed, so this is how the if condition work, if statements or if 68 00:05:12,460 --> 00:05:14,040 conditions are working. 69 00:05:14,050 --> 00:05:20,560 So whatever the condition we set here, that needs to be true in order to go inside and run this code 70 00:05:20,680 --> 00:05:22,350 so we can have multiple lines of code. 71 00:05:22,360 --> 00:05:28,300 For example, we can say for ABC it will be to ten. 72 00:05:28,720 --> 00:05:31,770 And if I can type it correctly. 73 00:05:31,780 --> 00:05:32,170 Right. 74 00:05:32,200 --> 00:05:39,490 So even I can do console that, lock that A, B, C if it is ten. 75 00:05:39,820 --> 00:05:47,230 So we can have multiple lines of code, but they will be executed only if this condition is met. 76 00:05:47,350 --> 00:05:49,060 When I say Matt means true. 77 00:05:49,330 --> 00:05:51,220 Now the second part else. 78 00:05:52,840 --> 00:05:54,830 Our statements, they're very important. 79 00:05:54,850 --> 00:05:57,320 So how are we arriving, El's statement? 80 00:05:57,340 --> 00:06:03,280 OK, so if no one is bigger now, I'm going to say then number two. 81 00:06:06,570 --> 00:06:11,290 Number two, then what I'm going to say here, I'm going to change a little bit. 82 00:06:11,610 --> 00:06:13,080 No one is bigger than number two. 83 00:06:13,110 --> 00:06:14,400 I'm going to copy this one. 84 00:06:15,930 --> 00:06:19,580 Just make sure that you copy everything in here. 85 00:06:19,590 --> 00:06:21,030 I'm putting the else condition. 86 00:06:21,030 --> 00:06:27,270 But what's most important for you to understand that we can't have here these brackets and set a new 87 00:06:27,270 --> 00:06:28,110 condition here? 88 00:06:28,350 --> 00:06:29,670 That is not how it works. 89 00:06:29,910 --> 00:06:35,260 So let me just finish this one and I will explain you how it will be executed. 90 00:06:35,340 --> 00:06:45,570 This means that number two is bigger than number one. 91 00:06:46,080 --> 00:06:49,100 OK, let's talk about it now. 92 00:06:49,350 --> 00:06:53,920 We do have the condition here and we say number one, which is waiting to be bigger than 30. 93 00:06:54,300 --> 00:06:56,250 This condition will be not true. 94 00:06:56,370 --> 00:07:00,090 So it will not go here and execute this block of code. 95 00:07:00,330 --> 00:07:01,350 What will happen? 96 00:07:01,500 --> 00:07:06,840 It will go straight to the alse condition and it will execute this line of code. 97 00:07:06,900 --> 00:07:08,260 Let's see if that is going to work. 98 00:07:09,150 --> 00:07:11,910 This means that number two is bigger than number one. 99 00:07:11,940 --> 00:07:12,450 Very good. 100 00:07:12,480 --> 00:07:20,510 So our logic is pretty much working because we just fixed the condition to our own needs. 101 00:07:20,640 --> 00:07:22,440 We say, OK, this will be the condition. 102 00:07:22,590 --> 00:07:27,340 And if it's not catched here, that means that number two is bigger than number one. 103 00:07:27,600 --> 00:07:29,400 So the line of code. 104 00:07:29,640 --> 00:07:33,640 So this is how it's usually been described. 105 00:07:33,930 --> 00:07:39,880 So block of code will be executed only if this first condition fails, for example. 106 00:07:39,930 --> 00:07:44,760 Now, if I changed back to this one, this here will be executed. 107 00:07:45,850 --> 00:07:47,820 Number two is bigger than number one, right. 108 00:07:48,420 --> 00:07:51,970 This will be executed and this will never be executed. 109 00:07:52,110 --> 00:07:58,460 So when this condition is true, it will go here and then it will never go in the air. 110 00:07:58,480 --> 00:07:59,820 So it will continue here. 111 00:08:00,060 --> 00:08:01,350 So let me show you. 112 00:08:01,860 --> 00:08:07,920 So it will skip the condition here outside of if else. 113 00:08:09,290 --> 00:08:16,610 Condition right when they hear this here, outside of Al's condition, even if you put it here, you 114 00:08:16,610 --> 00:08:23,570 see something here, it's not going to be catched because the first condition, if it's true, it will 115 00:08:23,570 --> 00:08:25,490 go here and it will do it. 116 00:08:25,940 --> 00:08:28,480 But let's change it like it was before. 117 00:08:28,730 --> 00:08:32,450 So that is pretty much about if and else condition. 118 00:08:32,470 --> 00:08:41,630 So let's check else if now, remember, I told you that here we cannot set a new condition, but with 119 00:08:41,630 --> 00:08:42,500 ALS, if. 120 00:08:42,500 --> 00:08:44,020 Yes, that is possible. 121 00:08:44,210 --> 00:08:49,100 So I'm going to copy again this one and let's change a couple of things. 122 00:08:49,340 --> 00:08:55,550 I'm going to leave this as it is so no one but I need to change here. 123 00:08:55,550 --> 00:08:59,510 And I will say no one is bigger than number two. 124 00:09:00,480 --> 00:09:00,850 Right. 125 00:09:01,580 --> 00:09:09,300 OK, now what I want here is to have another condition where I'm going to say make sure that you put 126 00:09:09,300 --> 00:09:10,380 the curly brackets here. 127 00:09:10,590 --> 00:09:14,160 So inside this condition, I would say number one. 128 00:09:15,460 --> 00:09:23,170 Is bigger than number three, right, and that is true, no one is bigger than number three because 129 00:09:23,170 --> 00:09:24,820 18 is always bigger than 16. 130 00:09:25,030 --> 00:09:27,150 So this here will be false. 131 00:09:27,460 --> 00:09:33,360 This condition will return false and it will skip this one and it will go to the elusive condition. 132 00:09:33,670 --> 00:09:36,500 Now, why it will go here, not there? 133 00:09:36,640 --> 00:09:38,710 Well, because here we have another condition. 134 00:09:39,010 --> 00:09:45,880 And so the block of coal will be executed if condition one fails and it's false. 135 00:09:46,060 --> 00:09:48,250 So now the condition, too, needs to be checked. 136 00:09:48,550 --> 00:09:52,660 OK, so yea I will see counsel that logged in. 137 00:09:52,660 --> 00:09:53,260 I will ride. 138 00:09:53,560 --> 00:10:01,890 This means no one is bigger than number three. 139 00:10:02,320 --> 00:10:02,740 Good. 140 00:10:03,220 --> 00:10:10,660 And we need to change the last part because if that is not true in our case, it is true here we can 141 00:10:10,660 --> 00:10:19,030 say this means no one is the smallest of all. 142 00:10:19,300 --> 00:10:23,680 Now here it will go and it will check. 143 00:10:23,680 --> 00:10:24,810 It will return false. 144 00:10:25,030 --> 00:10:29,500 This condition will never be executed, but it will go here and it will check No one. 145 00:10:29,500 --> 00:10:30,420 It's true. 146 00:10:30,640 --> 00:10:34,650 That is bigger than number three and it will print this line of code. 147 00:10:34,780 --> 00:10:37,120 So it will never go to the ALS condition. 148 00:10:37,150 --> 00:10:38,640 Let's save it and go back. 149 00:10:39,970 --> 00:10:40,900 Very nice. 150 00:10:41,170 --> 00:10:47,530 So our logic is working and now you know how to use if all else else if conditions. 151 00:10:47,740 --> 00:10:50,410 So we shall see if we can put another condition. 152 00:10:50,560 --> 00:10:55,390 For example, you want to check something extra that you haven't checked in the first one, then that's 153 00:10:55,390 --> 00:10:55,550 it. 154 00:10:55,840 --> 00:11:01,180 So these can be used to find which of the three numbers is the smallest. 155 00:11:01,330 --> 00:11:01,720 Right. 156 00:11:02,380 --> 00:11:06,730 So you can right here, this means that number three is the smallest of all. 157 00:11:06,910 --> 00:11:10,220 And it will be true because number three is going to be checked. 158 00:11:10,450 --> 00:11:13,930 Number one is bigger than number three. 159 00:11:14,170 --> 00:11:20,260 Yeah, but we can you can have multiple multiple combinations here of if alse conditions. 160 00:11:20,260 --> 00:11:20,560 Right. 161 00:11:20,980 --> 00:11:24,760 OK, now, last part, not actually the last part. 162 00:11:25,090 --> 00:11:26,850 Let's do another condition called switch. 163 00:11:27,610 --> 00:11:33,810 Now we use switch to specify many alternative blocks of code to be executed. 164 00:11:33,820 --> 00:11:40,240 So let's write how the if else conditions look like in real world world. 165 00:11:40,870 --> 00:11:43,350 And after that, we are just going to type it back. 166 00:11:43,660 --> 00:11:51,190 So for the here we do have if but here in switch, we need to use the key word switch. 167 00:11:51,430 --> 00:11:53,560 Now inside we will have expression. 168 00:11:53,890 --> 00:12:02,740 Now you know what expression means and we have case X column then code. 169 00:12:04,040 --> 00:12:07,130 Block will go here, then break. 170 00:12:07,430 --> 00:12:11,270 Let me just write it all, semicolon, then case. 171 00:12:12,950 --> 00:12:25,790 Why in Code Block, then we have a break and the last one is called default. 172 00:12:27,770 --> 00:12:30,500 And it will be called blog. 173 00:12:32,310 --> 00:12:43,560 And break nice, so that is pretty much how this is written, so the switch expression is evaluated 174 00:12:43,560 --> 00:12:44,400 only once. 175 00:12:44,760 --> 00:12:49,590 So this expression can be anything and you will see, for example, we can put a number here, we can 176 00:12:49,830 --> 00:12:58,680 put a condition here if we want inside, for example, five is greater than four, or we can just put 177 00:12:58,680 --> 00:12:59,910 anything that we want. 178 00:13:00,120 --> 00:13:03,320 And based on that expression, it's going to be evaluated at once. 179 00:13:03,600 --> 00:13:09,840 So the value of this expression is compared to the value of each case and the value of each case is 180 00:13:09,840 --> 00:13:10,670 going to be here. 181 00:13:10,860 --> 00:13:13,120 So we need to put our logic there. 182 00:13:13,410 --> 00:13:19,770 So if there is a match, for example, if I put X here and it will find there is X in this condition, 183 00:13:20,100 --> 00:13:26,060 block will be match, and if it's match, then the associate block of code will be executed. 184 00:13:26,310 --> 00:13:33,290 But we also need to have a break, because if we find a match, which is going to break from this, 185 00:13:33,300 --> 00:13:35,750 which expression it will go out here. 186 00:13:35,850 --> 00:13:40,900 So it will get out from this entire switch statement. 187 00:13:41,280 --> 00:13:47,610 So if there is if there is no match, for example, if I put for example, I have X and Y, if I put 188 00:13:47,610 --> 00:13:50,370 Z here, it will go through the first one. 189 00:13:50,620 --> 00:13:52,770 There is no match this value. 190 00:13:52,770 --> 00:13:55,050 It's not Z disvalue. 191 00:13:55,050 --> 00:13:57,090 It's not Y. 192 00:13:57,570 --> 00:14:01,080 Yeah, Y is not Z and it will go to the default. 193 00:14:01,320 --> 00:14:04,320 It will run the default block and that's it. 194 00:14:04,320 --> 00:14:08,460 It will get out in pretty much the speech expression is done. 195 00:14:08,860 --> 00:14:13,080 OK, so that is basically how this switch works. 196 00:14:13,080 --> 00:14:17,550 And this is pretty much the most complicated of all to understand. 197 00:14:18,450 --> 00:14:21,780 But when somebody explain to you like this, it's not. 198 00:14:21,780 --> 00:14:29,820 So let's create a variable here called DE in this program, we'll find the day of the week, for example, 199 00:14:29,820 --> 00:14:36,270 if today's a Sunday, and that is actually two days of Sunday in my place, the day that I'm recording 200 00:14:36,270 --> 00:14:36,570 this. 201 00:14:36,840 --> 00:14:44,430 So we will find that today based on the switch statement, we will find which day of the week is. 202 00:14:44,430 --> 00:14:49,470 But if you watch this video on Monday or Tuesday, you will have a different output. 203 00:14:49,470 --> 00:14:55,770 So don't worry if you see Sunday with mine and if you see Monday or Tuesday or any day of the week in 204 00:14:55,770 --> 00:14:56,300 your place. 205 00:14:56,310 --> 00:14:56,610 Right. 206 00:14:56,630 --> 00:15:01,510 So that doesn't mean that the CO is not working so far today. 207 00:15:02,520 --> 00:15:09,120 And what I'm going to use for the first time is I'm going to use a date function here and this date 208 00:15:09,480 --> 00:15:12,290 going to get day so we don't have to worry about this. 209 00:15:12,630 --> 00:15:19,520 Now, what this basically will tell us will return is actual number. 210 00:15:19,860 --> 00:15:22,890 So it will be zero to six. 211 00:15:22,890 --> 00:15:25,920 I believe it will be zero till six. 212 00:15:26,100 --> 00:15:27,750 So zero means Sunday. 213 00:15:28,320 --> 00:15:29,800 And I will just show you. 214 00:15:30,030 --> 00:15:30,840 So today. 215 00:15:32,460 --> 00:15:37,530 So this entire method, it's inbuilt and we can use it right out of the box. 216 00:15:37,530 --> 00:15:40,940 But you don't have to worry about this at this stage here. 217 00:15:41,520 --> 00:15:47,790 So today's Sunday, that's why it's going to give me zero so zero in Sunday one. 218 00:15:47,790 --> 00:15:55,140 It's Monday, Tuesday, three Wednesday for Thursday, five Friday and six Saturday now. 219 00:15:55,140 --> 00:16:01,680 Because I know what are the numbers, I can build the cases so I can say here, I'm going to put the 220 00:16:01,680 --> 00:16:02,020 date. 221 00:16:03,010 --> 00:16:04,590 Now let's do the switch. 222 00:16:05,550 --> 00:16:08,940 And inside expression, I can just create this variable. 223 00:16:09,960 --> 00:16:11,250 I can just put this variable. 224 00:16:11,250 --> 00:16:19,170 And I know that this variable will return a number either will be one zero one two three six doesn't 225 00:16:19,170 --> 00:16:19,400 matter. 226 00:16:19,410 --> 00:16:22,980 So it will return us a number so I can build these cases now. 227 00:16:22,980 --> 00:16:24,920 So everything will be easy. 228 00:16:24,930 --> 00:16:33,090 Now, let's say case zero and I will say de equal sun. 229 00:16:33,870 --> 00:16:34,500 Very good. 230 00:16:35,460 --> 00:16:39,410 Then we will have the break then another case, case one. 231 00:16:39,840 --> 00:16:45,030 So in case today was Monday, it will go here. 232 00:16:45,030 --> 00:16:48,050 In this case in what I have a block of code there. 233 00:16:48,480 --> 00:16:51,690 I will say de equal to Tuesday on Monday. 234 00:16:51,690 --> 00:16:52,050 Sorry. 235 00:16:53,260 --> 00:17:00,700 And break, then I'm going to copy and paste it now, look what I have done here just to clear the variable 236 00:17:00,700 --> 00:17:06,850 day, but I've never initialized to anything you can do that it will be rewritten here because you're 237 00:17:06,850 --> 00:17:08,130 going to put a new value there. 238 00:17:08,530 --> 00:17:10,620 So I haven't tell you this. 239 00:17:10,630 --> 00:17:12,370 For example, let's do it like this. 240 00:17:13,000 --> 00:17:14,740 If you put something here. 241 00:17:16,680 --> 00:17:17,070 Right. 242 00:17:17,080 --> 00:17:18,760 And if you cancel it, log. 243 00:17:20,800 --> 00:17:28,810 If you consulate log today day, but let me just first comment about this part now. 244 00:17:30,100 --> 00:17:37,300 I have something in store in the day variable, right, but that will change because in a switch statement, 245 00:17:37,690 --> 00:17:41,680 I'm declaring a new variable for the day variable. 246 00:17:41,680 --> 00:17:46,090 So I'm actually I'm declaring a new value for the day variable. 247 00:17:46,120 --> 00:17:46,430 Right. 248 00:17:46,750 --> 00:17:49,690 So whatever we have here, it will be overridden. 249 00:17:50,260 --> 00:17:53,500 OK, now let's do the rest of the blocks. 250 00:17:53,770 --> 00:17:55,000 So I'm just going to copy them. 251 00:17:56,080 --> 00:17:59,180 And I knew that it will mess it up a little bit. 252 00:18:00,940 --> 00:18:01,220 Right. 253 00:18:01,750 --> 00:18:07,910 OK, that's why I don't want to copy and paste too much, but so zero one it will be too. 254 00:18:08,350 --> 00:18:11,440 This will be three and Tuesday. 255 00:18:13,900 --> 00:18:19,910 And this will be Wednesday, so you can you can use anything you want. 256 00:18:19,930 --> 00:18:22,090 You can say short Wednesday. 257 00:18:24,230 --> 00:18:26,870 Now, let's face this one. 258 00:18:28,330 --> 00:18:33,740 A couple more times here, so case zero, one, two, three, then. 259 00:18:36,230 --> 00:18:45,440 Uh, this will be for this will be Phibes five and this will be six, and we are done, ladies and gentlemen, 260 00:18:45,650 --> 00:18:47,840 so four will be Thursday. 261 00:18:50,380 --> 00:18:55,330 And number five will be Friday, number six will be. 262 00:18:56,650 --> 00:18:57,400 Saturday. 263 00:19:01,070 --> 00:19:12,230 And you can put it here, default, so if there is a some number, but it will not happen, but if you 264 00:19:12,230 --> 00:19:15,890 put here manually seven, we are not getting anything seven. 265 00:19:16,040 --> 00:19:19,390 So we need to specify our default code block here. 266 00:19:19,520 --> 00:19:28,810 So the default statement will say they equal something went wrong. 267 00:19:30,680 --> 00:19:34,710 And Rick, that is pretty much it. 268 00:19:35,120 --> 00:19:35,540 So. 269 00:19:36,820 --> 00:19:41,700 What is the last thing we need to do to control it, like the day of the week? 270 00:19:42,400 --> 00:19:42,880 Nice. 271 00:19:43,940 --> 00:19:50,090 OK, so let's go through this statement one more so the Swedish statement, we said the expression here 272 00:19:50,300 --> 00:19:55,340 and this expression, this function will return from zero until six. 273 00:19:55,610 --> 00:19:59,720 And because of that, we build the cases zero until six. 274 00:19:59,990 --> 00:20:04,750 And if today's zero, it will go here, it will match this value. 275 00:20:04,880 --> 00:20:08,360 So make sure that you are you understanding this part. 276 00:20:08,360 --> 00:20:16,340 Whatever we put here, if we put high here, we need to have high here as well in order to get in this 277 00:20:16,340 --> 00:20:22,340 part before in the past, when I was learning this while I was a little bit confused because no one 278 00:20:22,340 --> 00:20:26,030 told me so, they just gave us exercises to do. 279 00:20:26,030 --> 00:20:29,660 And I was just confused why how is this working? 280 00:20:29,660 --> 00:20:36,740 But now, you know, so based on this, the value of this expression, it will be matched in and in 281 00:20:36,740 --> 00:20:37,820 one of these condition. 282 00:20:37,940 --> 00:20:40,120 If not, the default will kick in. 283 00:20:40,430 --> 00:20:45,290 OK, and inside we setting the date to before was something. 284 00:20:45,290 --> 00:20:50,040 Now we sitting to Sunday, Monday, Tuesday, Wednesday and so on, so forth. 285 00:20:50,090 --> 00:20:51,050 OK, save it. 286 00:20:52,100 --> 00:20:57,280 Now, let's go back here and it's going to say Sunday because today is really Sunday. 287 00:20:57,710 --> 00:20:58,700 Very good. 288 00:20:59,090 --> 00:21:02,720 And I'm not I don't need to control the clock here. 289 00:21:02,900 --> 00:21:05,630 So that is pretty much about the switch statement. 290 00:21:06,780 --> 00:21:11,020 The last thing that I want to explain is ternary operator. 291 00:21:12,240 --> 00:21:17,210 Now, this is a basically pretty much new but I just want to include it here. 292 00:21:17,550 --> 00:21:22,460 So for the ternary operator, we have something like this condition. 293 00:21:22,980 --> 00:21:26,520 Then we have a question mark, then we have expression. 294 00:21:26,970 --> 00:21:36,780 If true, then we have Callon here, an expression if false. 295 00:21:38,700 --> 00:21:40,500 And this is pretty much confusing, right? 296 00:21:40,800 --> 00:21:50,930 So this operator is frequently used as a short cut of this weight of this if statement, if else. 297 00:21:50,970 --> 00:21:51,270 Right. 298 00:21:51,600 --> 00:21:53,580 So we have a condition here. 299 00:21:54,000 --> 00:21:58,890 We're saying if this condition is true, then do this block of code else do this block of code. 300 00:21:58,920 --> 00:21:59,280 Well. 301 00:22:00,570 --> 00:22:05,210 That is pretty much it, but we are going to do in one single line, we are setting the conditions first. 302 00:22:05,400 --> 00:22:09,420 The question mark, if the condition is true, Will will go to this one. 303 00:22:09,690 --> 00:22:16,010 And this column here means if the condition is false, whatever we put here, it will be executed. 304 00:22:16,260 --> 00:22:24,390 Well, let's, for example, set some person age to be twenty six and check if he can drink beer or 305 00:22:24,390 --> 00:22:26,100 juice based on his age. 306 00:22:26,280 --> 00:22:31,050 So I'm going to say var variable my age and let's put it here. 307 00:22:31,050 --> 00:22:31,710 Twenty six. 308 00:22:31,720 --> 00:22:36,240 You can always practice this with prompt, you can prompt the user for age and. 309 00:22:36,240 --> 00:22:38,850 Yeah but today I don't have time to do this. 310 00:22:39,060 --> 00:22:45,810 Now I'm going to say beverage and here I'm going to set the condition actually. 311 00:22:47,240 --> 00:22:48,180 I'm doing this. 312 00:22:48,320 --> 00:22:56,540 Let me just show you first so we can do it like this, my age is greater or equal to twenty six, but 313 00:22:56,540 --> 00:22:58,520 it will work with greater only. 314 00:22:58,790 --> 00:22:59,640 Just want to be sure. 315 00:23:00,320 --> 00:23:08,990 Then the question mark, I can have a beer and else I will have juice. 316 00:23:11,000 --> 00:23:12,780 And that's pretty much it. 317 00:23:13,130 --> 00:23:22,220 Now, the output of this, I just want to store it in a variable called beverage and what will happen. 318 00:23:22,230 --> 00:23:24,060 So my age is 26. 319 00:23:24,380 --> 00:23:27,950 It will go here and it will say, OK, here should be twenty one. 320 00:23:28,490 --> 00:23:30,410 Right to always be. 321 00:23:30,680 --> 00:23:31,660 So twenty six. 322 00:23:32,270 --> 00:23:35,050 So I'm saying twenty six is bigger or equal to twenty one. 323 00:23:35,270 --> 00:23:40,240 It's bigger, it's not equal but it's bigger than twenty one because that condition is true. 324 00:23:40,670 --> 00:23:45,980 We are going to do this part and this part is the if condition. 325 00:23:45,980 --> 00:23:46,320 Right. 326 00:23:46,820 --> 00:23:51,080 If that was not true, I will only be allowed to drink juice. 327 00:23:51,080 --> 00:23:55,160 So beverage will hold beer, not juice. 328 00:23:55,310 --> 00:23:58,100 Because this condition is true and we need true. 329 00:23:58,100 --> 00:24:02,760 We have this expression then if we have something else then we're going to have false conditions. 330 00:24:02,780 --> 00:24:05,920 OK, now control it like the beverage. 331 00:24:07,490 --> 00:24:08,060 Save it. 332 00:24:09,370 --> 00:24:09,980 Here he is. 333 00:24:10,000 --> 00:24:10,910 I do have a beer. 334 00:24:11,110 --> 00:24:14,230 What if what will happen if I have 20 years? 335 00:24:15,700 --> 00:24:23,260 Now, the condition is false and expression is false will be this after this column here. 336 00:24:24,180 --> 00:24:28,950 And I will have juice because a minor I can't drink now. 337 00:24:29,040 --> 00:24:37,590 That is called ternary operator and we usually use this operator as a short version of if our statement 338 00:24:37,950 --> 00:24:39,660 that is pretty much it. 339 00:24:40,120 --> 00:24:43,740 Now, last part, we will do logical operators 340 00:24:47,130 --> 00:24:51,630 and we're going to start wi and now this is a very, very nice. 341 00:24:52,290 --> 00:25:00,800 In order for you to understand, I'm going to say our first first name and that will be Tom, Tom and 342 00:25:00,900 --> 00:25:02,630 Vau last name. 343 00:25:03,030 --> 00:25:05,400 Let me just write this one cruise. 344 00:25:07,000 --> 00:25:17,200 I hope I spelled his last name correctly, if a first name is equal, equal to Hoopes, this means equal 345 00:25:17,830 --> 00:25:20,500 in to Tom. 346 00:25:21,870 --> 00:25:27,000 And last name is equal, equal to Crewes. 347 00:25:29,160 --> 00:25:36,210 And let me just write this one down and we can just talk it, what will happen while we have a famous 348 00:25:37,020 --> 00:25:38,710 by the way, you can write anything you want to hear. 349 00:25:38,970 --> 00:25:39,660 Actor. 350 00:25:42,160 --> 00:25:42,670 Here. 351 00:25:43,710 --> 00:25:45,690 Doing JavaScript. 352 00:25:48,520 --> 00:25:49,520 Nice. 353 00:25:50,440 --> 00:25:50,970 OK. 354 00:25:51,820 --> 00:25:52,480 Ls. 355 00:25:54,840 --> 00:25:57,780 Council that long form. 356 00:25:59,400 --> 00:26:02,760 Get back here and start working. 357 00:26:05,590 --> 00:26:08,460 It is an exclamation mark because we are yelling at him. 358 00:26:09,600 --> 00:26:10,830 That's not good, right? 359 00:26:11,700 --> 00:26:13,650 We not like that, we're not yelling to anyone. 360 00:26:14,270 --> 00:26:18,680 OK, now pretty much this may be a confusing so what we did. 361 00:26:18,990 --> 00:26:20,420 So we create two variables. 362 00:26:20,550 --> 00:26:23,370 First one is the first name it will hold value to. 363 00:26:23,820 --> 00:26:25,740 The second one is the last name. 364 00:26:25,740 --> 00:26:32,070 It will hold value of cruise hits its last name right now what we are doing here. 365 00:26:32,400 --> 00:26:38,800 So we are using logical operators in combination with the JavaScript operator. 366 00:26:39,180 --> 00:26:46,380 Yeah, we are using in combination with JavaScript conditionals with any of this right now why we are 367 00:26:46,380 --> 00:26:46,920 doing this. 368 00:26:47,250 --> 00:26:54,990 So when I have these and means what I have in the first condition needs to be true and what I have in 369 00:26:54,990 --> 00:26:59,580 the second condition needs to be true in order to execute this code of block. 370 00:26:59,790 --> 00:27:06,120 So both of these cases here, the first one, the one that I have on the left from the end operator 371 00:27:06,660 --> 00:27:07,800 needs to be true. 372 00:27:08,040 --> 00:27:08,430 Right? 373 00:27:08,820 --> 00:27:10,170 So that is how it's working. 374 00:27:10,170 --> 00:27:16,560 And in our case, our first name is true for Tom and our last name is true. 375 00:27:16,650 --> 00:27:17,760 It's Kroos. 376 00:27:18,060 --> 00:27:22,080 So it should go here and say, wow, we have a famous actor. 377 00:27:22,410 --> 00:27:23,200 That's pretty much it. 378 00:27:23,520 --> 00:27:30,630 Now, if I, for example, say here that the first name should be Tommy and the last name should be. 379 00:27:31,500 --> 00:27:33,090 Well, this is not true. 380 00:27:33,090 --> 00:27:37,050 The first name holds Tom and this condition will be false. 381 00:27:37,200 --> 00:27:43,380 So I have false and true and false and true will always get me back false. 382 00:27:43,500 --> 00:27:45,510 So it will not go here. 383 00:27:45,510 --> 00:27:47,970 It will be catched in the condition. 384 00:27:47,970 --> 00:27:50,310 Tom, get back here and start working. 385 00:27:50,310 --> 00:27:52,740 So this is how the end operator works. 386 00:27:52,980 --> 00:28:01,910 Both sides of this line here needs to be true in order to order this code or block to be executed. 387 00:28:02,220 --> 00:28:05,850 OK, now I'm going to copy the same thing again. 388 00:28:06,390 --> 00:28:10,740 And, uh, let's change this one to order. 389 00:28:12,090 --> 00:28:14,280 And I'm not going to redeclared him again. 390 00:28:14,610 --> 00:28:14,770 Right. 391 00:28:14,880 --> 00:28:17,100 That's not a good point in here. 392 00:28:17,100 --> 00:28:20,280 Change the end with or now. 393 00:28:21,330 --> 00:28:24,060 If I do it like that, I will have the same same output. 394 00:28:24,060 --> 00:28:24,420 Why? 395 00:28:24,720 --> 00:28:32,290 Because war means only one of the condition doesn't matter if this or this needs to be true in order 396 00:28:32,290 --> 00:28:33,630 for this block to be executed. 397 00:28:33,690 --> 00:28:34,500 It's only one. 398 00:28:34,650 --> 00:28:37,650 For example, if I put here Tommy, that is false. 399 00:28:37,950 --> 00:28:39,480 But this one is true. 400 00:28:39,840 --> 00:28:45,030 So other means just I need any of this condition to be true in order to get here. 401 00:28:45,720 --> 00:28:47,820 And yet we do have the same result. 402 00:28:48,000 --> 00:28:55,950 So any only one, only one scenario is possible to go to the condition when this is both of the conditions 403 00:28:55,950 --> 00:28:56,190 here. 404 00:28:56,190 --> 00:28:57,630 Are we doing we are checking. 405 00:28:57,630 --> 00:28:59,310 They are not true. 406 00:28:59,910 --> 00:29:01,770 And that will go back there. 407 00:29:01,980 --> 00:29:09,090 So Tommy and Cruz, they're not same what we have stored here in this variable now, you know, the 408 00:29:09,090 --> 00:29:10,170 power of. 409 00:29:11,170 --> 00:29:16,090 And I'm going to leave it like this with one mistake here, because you need to know, so that is pretty 410 00:29:16,090 --> 00:29:16,490 much it. 411 00:29:16,900 --> 00:29:20,200 Now, I can see here two of the conditions. 412 00:29:22,390 --> 00:29:35,290 Only one of the conditions can be only one of the conditions needs to be true in order to execute the 413 00:29:35,470 --> 00:29:36,330 if block. 414 00:29:37,690 --> 00:29:38,070 Right. 415 00:29:38,110 --> 00:29:42,340 And I'm going to copy the same thing in here. 416 00:29:42,340 --> 00:29:53,080 It's different to the condition to two of the condition needs to be true in order to execute the IV 417 00:29:53,080 --> 00:29:54,120 like cool. 418 00:29:54,550 --> 00:30:00,500 And the last one is just going to copy this one again and let's change it. 419 00:30:00,730 --> 00:30:02,320 This should be exclamation mark. 420 00:30:02,320 --> 00:30:04,030 End means not. 421 00:30:05,280 --> 00:30:13,620 OK, so what not does pretty much interesting, so let's I don't need here to conditions for this one 422 00:30:13,620 --> 00:30:17,250 to explain it and we're going to do more in future. 423 00:30:18,180 --> 00:30:22,800 So don't worry about it, so we're going to do more in future with not so you're going to have more 424 00:30:22,800 --> 00:30:26,970 practice and if you don't understand it right now, you just don't need to freak out. 425 00:30:27,000 --> 00:30:28,180 That's what I'm trying to say. 426 00:30:28,600 --> 00:30:34,970 OK, now I'm going to say it like this, and I'm just going to cut it from here. 427 00:30:34,980 --> 00:30:36,810 I'm going to say exclamation mark. 428 00:30:37,020 --> 00:30:40,510 I'm going to put another pair of brackets, put the condition there. 429 00:30:40,710 --> 00:30:42,930 So first name equal to Tom. 430 00:30:42,960 --> 00:30:43,950 Let's change this one. 431 00:30:44,640 --> 00:30:46,140 And I will say Conjola. 432 00:30:47,880 --> 00:30:49,230 Hi, Tom. 433 00:30:50,520 --> 00:30:56,730 Make sure that high capital H looks doesn't look good in here. 434 00:30:57,150 --> 00:30:58,830 Who are you? 435 00:30:58,830 --> 00:31:01,360 If you're not Tom, then who are you in questionmark. 436 00:31:01,650 --> 00:31:02,050 Right. 437 00:31:02,460 --> 00:31:03,670 So what do you think will happen? 438 00:31:03,690 --> 00:31:04,570 Let's go back here. 439 00:31:05,130 --> 00:31:05,880 Who are you? 440 00:31:06,600 --> 00:31:07,020 Well. 441 00:31:08,320 --> 00:31:13,120 Let me just copy this one first name here just to explain this one. 442 00:31:13,900 --> 00:31:14,760 So first name? 443 00:31:15,040 --> 00:31:19,330 Well, first name, it's Tom and it's equal to Tom. 444 00:31:19,520 --> 00:31:20,620 So what is happening? 445 00:31:20,650 --> 00:31:27,370 Well, we have this not and what this operate what this operator logical operator would do. 446 00:31:27,370 --> 00:31:39,010 It will do will turn true condition to false and false to true. 447 00:31:39,400 --> 00:31:47,110 Now because I have it here and this entire thing doesn't matter with the operator needs to be true in 448 00:31:47,110 --> 00:31:47,950 order to get here. 449 00:31:47,950 --> 00:31:54,690 But the first part was true and say the first name is pretty much equal to the value system. 450 00:31:55,000 --> 00:31:59,070 But here I just say Nannygate make that opposite. 451 00:31:59,350 --> 00:32:01,190 So if it's true, make it false. 452 00:32:01,240 --> 00:32:06,460 So if this condition is false, then this will never be executed. 453 00:32:06,460 --> 00:32:07,360 It will go here. 454 00:32:07,660 --> 00:32:11,510 So make sure that you understand this part if we have here, Tommy. 455 00:32:12,490 --> 00:32:13,850 Now, look, how bizarre is this. 456 00:32:15,070 --> 00:32:22,200 So if we have here, Tommy, and this is not true, but here with the the not operator will say, yeah, 457 00:32:22,210 --> 00:32:24,880 now the false I will make it true. 458 00:32:25,030 --> 00:32:28,060 If if true, then I will do this part. 459 00:32:28,390 --> 00:32:29,260 Say hi, Tom. 460 00:32:30,000 --> 00:32:30,360 Right. 461 00:32:30,880 --> 00:32:37,420 So make sure that you understand the not operator will turn every anything that we have here to the 462 00:32:37,420 --> 00:32:38,170 opposite value. 463 00:32:38,170 --> 00:32:39,970 If it's true, it will turn into false. 464 00:32:40,120 --> 00:32:42,250 If it's false, it will turn out to true. 465 00:32:42,460 --> 00:32:43,960 And that is pretty much it. 466 00:32:44,140 --> 00:32:45,310 We will do much, much more. 467 00:32:45,310 --> 00:32:46,630 And you have exercises. 468 00:32:46,630 --> 00:32:47,290 Please do them. 469 00:32:47,740 --> 00:32:49,930 So let me just recap what we have done. 470 00:32:50,140 --> 00:32:55,630 We have done all of these conditionals and we have included these logical operators. 471 00:32:55,840 --> 00:33:02,980 And yeah, that is pretty much it for the if to be this code of block to be executed, this condition 472 00:33:02,990 --> 00:33:03,850 should be true. 473 00:33:04,270 --> 00:33:11,890 And the keyword is if now when we have else, when this condition is not true, the else kicks in and 474 00:33:11,890 --> 00:33:14,650 the code of lock here that we have will be executed. 475 00:33:14,830 --> 00:33:23,470 The else if if we use or else if we always use in a combination with if y because this condition, if 476 00:33:23,470 --> 00:33:27,700 this condition is not true, it will go to check the second condition that we said. 477 00:33:27,850 --> 00:33:31,180 And even if that is not true, it will go to the LS. 478 00:33:31,180 --> 00:33:33,940 But if it's true, it will print out here. 479 00:33:34,180 --> 00:33:36,790 The switch statement requires an expression. 480 00:33:37,030 --> 00:33:44,680 Wherever we have here in this expression needs to be found it in the cases so case X and Y so needs 481 00:33:44,680 --> 00:33:45,280 to be matched. 482 00:33:45,280 --> 00:33:46,720 And that's why we did here. 483 00:33:47,020 --> 00:33:49,090 They but I'm just going to delete here. 484 00:33:49,090 --> 00:33:51,610 I'm just going to leave it like they just like that. 485 00:33:52,260 --> 00:33:53,230 It is Sunday. 486 00:33:53,410 --> 00:33:58,370 Now this is working because here we just declaring the value based on the expressions. 487 00:33:58,390 --> 00:34:05,410 If the expression is zero it will go here at zero and the function here and you date that get they will 488 00:34:05,410 --> 00:34:08,320 always return from zero till six. 489 00:34:08,590 --> 00:34:14,680 And that is why we can just create this switch statement and find out what day of the week we are at 490 00:34:14,680 --> 00:34:15,240 the moment. 491 00:34:15,430 --> 00:34:21,580 So in your when you watching this video, if you watching on Tuesday, you will have a different you 492 00:34:21,580 --> 00:34:27,640 will have two and then you will need to probably the output will be Tuesday here. 493 00:34:27,640 --> 00:34:29,620 So don't be afraid. 494 00:34:29,620 --> 00:34:33,160 If you don't see Sunday as me, that's pretty much it for this weekend. 495 00:34:33,160 --> 00:34:36,150 And we did the ternary operator. 496 00:34:36,150 --> 00:34:38,970 Are we going to do this operator in future semicolon here? 497 00:34:38,970 --> 00:34:44,650 I did forget that part and make sure that you're not doing the mistakes that I do. 498 00:34:44,830 --> 00:34:46,350 OK, I will see this one. 499 00:34:46,360 --> 00:34:48,520 This was super long and I'm so sorry about this.