1 00:00:00,520 --> 00:00:06,250 Welcome back, this is less than 11 switched statements, so suwit statements are very similar to IFLA 2 00:00:06,250 --> 00:00:12,010 statements in that you are going to perform different actions based on different conditions, but they're 3 00:00:12,010 --> 00:00:13,120 much more flexible. 4 00:00:13,390 --> 00:00:17,080 The basic keyword will stop the code when the condition is met. 5 00:00:17,350 --> 00:00:21,580 So similar to an if else, you know, one condition can happen. 6 00:00:21,580 --> 00:00:27,820 But the difference here is that with case, you're allowed to do multiple conditions at the same time. 7 00:00:27,830 --> 00:00:34,630 So if it's strawberry or raspberry, then it perform this section of code. 8 00:00:34,930 --> 00:00:40,000 If it's blueberry, this section BEININ in this section and then a switch statement needs a default 9 00:00:40,000 --> 00:00:42,700 at the end, which is like that else in the NFL's. 10 00:00:43,750 --> 00:00:48,070 That will execute a block of code if the conditions are not met. 11 00:00:48,440 --> 00:00:51,610 OK, so let's take a look at it in JavaScript. 12 00:00:52,780 --> 00:00:53,320 All right. 13 00:00:53,330 --> 00:00:54,760 So let's start with. 14 00:00:57,500 --> 00:01:09,630 Start with a contest, fruit is strawberry, and let's do our switch case, so switch fruit, so it's 15 00:01:09,630 --> 00:01:12,540 going to check the value that set for fruit. 16 00:01:14,580 --> 00:01:21,210 And then in different cases, when we say in English, that's not the case, know we're talking about 17 00:01:21,210 --> 00:01:22,350 different scenarios. 18 00:01:23,250 --> 00:01:28,770 So in the case where it's strawberry, it will move on. 19 00:01:29,490 --> 00:01:31,020 And in the case where it's. 20 00:01:32,900 --> 00:01:33,920 Rasberry. 21 00:01:39,090 --> 00:01:43,020 They will execute this block of code here. 22 00:01:50,610 --> 00:01:51,430 Throughputs. 23 00:01:55,660 --> 00:01:57,880 Is red. 24 00:02:00,540 --> 00:02:11,220 And then we have to break have it jump out of the entire logic at that point, and then we go to case 25 00:02:11,220 --> 00:02:12,630 where blueberry. 26 00:02:17,920 --> 00:02:29,350 Instead, we're going to see blue and then we're going to see a case where banana. 27 00:02:35,860 --> 00:02:40,150 We see a banana is yellow. 28 00:02:42,280 --> 00:02:48,520 And then we have to end it with a default and inside my default, I can say. 29 00:02:57,160 --> 00:02:58,870 I can see I don't know. 30 00:03:05,240 --> 00:03:11,870 I don't know what the color of I don't know what color. 31 00:03:14,490 --> 00:03:19,740 The something is that's come up with another one. 32 00:03:20,820 --> 00:03:24,720 OK, so if this is the case, let's just test it out, see what happens. 33 00:03:25,840 --> 00:03:30,610 Strawberry is red or raspberry. 34 00:03:32,890 --> 00:03:33,670 Is red 35 00:03:36,490 --> 00:03:37,840 a blueberry? 36 00:03:41,280 --> 00:03:55,380 Is blue, banana is yellow, and if I put in some other thing like apple, I don't know what color the 37 00:03:55,380 --> 00:03:57,250 apple is awesome. 38 00:03:57,270 --> 00:03:59,270 So this is exactly what we wanted to see. 39 00:04:00,000 --> 00:04:03,930 As you can see, this is a little bit more flexible than an if statement. 40 00:04:04,500 --> 00:04:11,340 It's actually preferred in a variety of cases when you're developing in JavaScript to use which case 41 00:04:11,760 --> 00:04:18,270 instead of using NFLs, and you can certainly use it AFL's and where you could use the ternary operator 42 00:04:18,900 --> 00:04:22,530 and you could nest ternary operations and nest if else statements. 43 00:04:23,670 --> 00:04:29,700 To get where you need to go and to do a very similar logic, but in which case definitely simplifies 44 00:04:30,210 --> 00:04:36,840 some situations where you want to have a similar format in many cases and different formats in other 45 00:04:36,840 --> 00:04:37,390 cases. 46 00:04:37,770 --> 00:04:39,650 So there you go. 47 00:04:39,840 --> 00:04:44,940 And then obviously you can get switch case structures that are much more complex than this. 48 00:04:45,390 --> 00:04:47,250 But this is a great example to get started. 49 00:04:48,210 --> 00:04:48,570 All right. 50 00:04:48,700 --> 00:04:50,480 That's it for Section four. 51 00:04:50,490 --> 00:04:52,830 We're going to move on to our code challenge in the next video.