1
00:00:00,390 --> 00:00:04,890
You guys this should be kind of a quick video we're just going to talk about switches real quick which

2
00:00:04,890 --> 00:00:05,910
are pretty easy.

3
00:00:05,910 --> 00:00:09,510
It's just another way to validate conditions.

4
00:00:09,900 --> 00:00:14,820
So we're going to kind of do what we did with the colors in the IF statements in the last video except

5
00:00:14,820 --> 00:00:21,150
we're going to use switches so let's create a color here and let's make it red.

6
00:00:21,360 --> 00:00:21,870
All right.

7
00:00:21,870 --> 00:00:27,830
Instead of using if else what we're going to do is we're going to use a switch.

8
00:00:29,020 --> 00:00:33,070
And here is what we want to test and what we want to test is the color.

9
00:00:33,390 --> 00:00:40,470
OK so inside of a switch what you want to do is define cases different cases So let's say we have a

10
00:00:40,470 --> 00:00:43,700
case where it's red right.

11
00:00:43,710 --> 00:00:49,650
And then the syntax is to put a colon here and then we're going to do whatever it is we want to do if

12
00:00:49,650 --> 00:00:50,160
it's red.

13
00:00:50,160 --> 00:00:57,670
In this case we're just going to console log and we'll say color is red.

14
00:00:57,990 --> 00:00:58,390
All right.

15
00:00:58,410 --> 00:01:02,000
And then we're going to want to break from that case.

16
00:01:02,070 --> 00:01:02,460
All right.

17
00:01:02,460 --> 00:01:10,490
Let's put another case if it's blue colon will console log

18
00:01:13,370 --> 00:01:16,210
and will say color is blue.

19
00:01:16,650 --> 00:01:18,620
And then we want to break.

20
00:01:19,460 --> 00:01:19,890
OK.

21
00:01:19,890 --> 00:01:25,020
Now we can keep going we can do other colors if we want but when we come to an end what we'll do is

22
00:01:25,020 --> 00:01:37,020
have a default case will say default colon and then let's to console the log will say color is not red

23
00:01:37,050 --> 00:01:38,300
or blue.

24
00:01:38,790 --> 00:01:40,440
OK.

25
00:01:41,750 --> 00:01:43,020
And then we'll break.

26
00:01:43,410 --> 00:01:51,470
So let's go ahead and save this and if we look down here we get color as red if we change it to blue.

27
00:01:51,660 --> 00:01:53,670
Save it we get color is blue.

28
00:01:53,850 --> 00:01:58,420
If we change it to yellow and save it we get color is not red or blue.

29
00:01:58,620 --> 00:01:59,130
OK.

30
00:01:59,310 --> 00:02:05,130
So it does exactly what the if else or the LCF did in the last video.

31
00:02:05,130 --> 00:02:07,550
It's just a different way of doing things.

32
00:02:07,550 --> 00:02:07,940
All right.

33
00:02:07,950 --> 00:02:14,010
Now switches I would suggest using a switch and you have a lot of different cases rather than doing

34
00:02:14,010 --> 00:02:15,980
you know else if else if else.

35
00:02:16,200 --> 00:02:18,990
I think a switch is better in that situation.

36
00:02:19,470 --> 00:02:21,960
So let's do one more thing here with switches.

37
00:02:22,040 --> 00:02:30,810
What I'm going to do is what I want to evaluate here is the day of the week so remember with dates we

38
00:02:30,810 --> 00:02:32,270
can say new day.

39
00:02:32,760 --> 00:02:36,990
And then we can use the get day method.

40
00:02:36,990 --> 00:02:40,640
All right so that's going to give us the day of the week in number form.

41
00:02:40,650 --> 00:02:42,720
OK starting with 0 for Sunday.

42
00:02:42,720 --> 00:02:47,030
So what I'll do is I'll say case 0.

43
00:02:47,670 --> 00:02:50,400
And let's set a variable here.

44
00:02:50,400 --> 00:02:59,070
Actually Will we'll set the variables say Let day and then down here will say day equals

45
00:03:01,590 --> 00:03:06,070
Sunday OK and then we'll set a break.

46
00:03:09,360 --> 00:03:11,320
You will indent that.

47
00:03:11,650 --> 00:03:12,030
All right.

48
00:03:12,050 --> 00:03:19,820
And then I'm just going to copy this and we're going to mess up the indents here but that's all right

49
00:03:19,820 --> 00:03:29,090
and I'll fix it after sort of I've got one two three four five six seven and then we'll just bring back

50
00:03:30,230 --> 00:03:31,390
these cases

51
00:03:34,380 --> 00:03:42,750
I saw 0 1 2 3 4 5 and 6.

52
00:03:42,750 --> 00:03:44,650
All right so this would be Monday.

53
00:03:50,270 --> 00:03:51,050
Tuesday

54
00:04:00,360 --> 00:04:04,650
Friday and Saturday.

55
00:04:05,500 --> 00:04:06,170
OK.

56
00:04:06,330 --> 00:04:14,910
So now we have our switch and then let's go ahead and at the end here will console dot blog and let's

57
00:04:14,910 --> 00:04:22,790
put a template literal in here and we'll say today is and then we'll put our day variables so let's

58
00:04:22,790 --> 00:04:25,980
save and we get today's Thursday.

59
00:04:26,100 --> 00:04:26,490
All right.

60
00:04:26,490 --> 00:04:28,320
Which is true.

61
00:04:28,320 --> 00:04:31,740
You can see right here Thursday.

62
00:04:31,750 --> 00:04:37,210
All right so I'm not going to go much more into this which is pretty easy to understand in the next

63
00:04:37,210 --> 00:04:37,910
video.

64
00:04:37,930 --> 00:04:41,190
We're going to be taking a look at functions.

65
00:04:41,260 --> 00:04:46,490
Now we're going to look at function declarations and function expressions.

66
00:04:46,510 --> 00:04:48,680
All right so I will see you in the next video.

