1
00:00:00,560 --> 00:00:01,700
OK, welcome back.

2
00:00:01,820 --> 00:00:08,020
Now we're going to do the solution for Section four code challenge, so let's take a look at a few possibilities

3
00:00:08,420 --> 00:00:08,660
now.

4
00:00:08,660 --> 00:00:09,830
This could be anything, of course.

5
00:00:09,840 --> 00:00:11,740
So let's just start with our statement.

6
00:00:12,140 --> 00:00:20,000
Let's get a page here and let's just put thirty three.

7
00:00:22,600 --> 00:00:33,490
So a regular if statement would be something like if age is greater than thirty three, then console

8
00:00:33,490 --> 00:00:34,210
log.

9
00:00:41,650 --> 00:00:47,580
I am now middle aged and maybe middle age is a little bit older.

10
00:00:47,620 --> 00:00:50,410
Let's just go with it and then else.

11
00:00:53,960 --> 00:00:55,250
We could just say

12
00:00:58,480 --> 00:00:59,330
that long.

13
00:01:00,650 --> 00:01:02,270
I'm still young yet.

14
00:01:04,910 --> 00:01:07,540
All right, so let's just try that out.

15
00:01:08,990 --> 00:01:16,970
And I would get I'm still young yet because the age is set to thirty three and that's not more than

16
00:01:17,120 --> 00:01:19,220
thirty three, let's change changes to forty.

17
00:01:20,130 --> 00:01:24,740
OK, so let's go forty five.

18
00:01:25,580 --> 00:01:27,710
And we test that now.

19
00:01:27,710 --> 00:01:30,050
Middle aged Bactine.

20
00:01:30,050 --> 00:01:30,830
Thirty three.

21
00:01:31,790 --> 00:01:32,780
I'm still young yet.

22
00:01:32,960 --> 00:01:33,620
OK, great.

23
00:01:34,700 --> 00:01:37,090
So we can do something else with that.

24
00:01:37,100 --> 00:01:37,790
Thirty three.

25
00:01:37,790 --> 00:01:51,410
We could say if we could start with this same if and do it agisting else if in the middle elusive age

26
00:01:53,180 --> 00:01:55,310
equals thirty three.

27
00:01:59,510 --> 00:02:02,590
Hey, that's how old I am.

28
00:02:07,050 --> 00:02:11,930
And then else we can keep this email statement, OK?

29
00:02:16,820 --> 00:02:23,180
All right, so since our age value is thirty three, that's what we get if we change to thirty two,

30
00:02:23,180 --> 00:02:25,430
it would be the same as the previous one.

31
00:02:27,050 --> 00:02:33,680
Now, since it's thirty three, it's it's falling into this elusive condition right now.

32
00:02:33,680 --> 00:02:37,300
Let's convert these into ternary statements.

33
00:02:37,310 --> 00:02:41,720
So how do we convert this first one into a ternary statement.

34
00:02:41,750 --> 00:02:45,860
Well we would have to take this first conditional expression right here.

35
00:02:48,080 --> 00:03:00,110
And then you do questionmark and then we do the one case and then we do the other case.

36
00:03:08,430 --> 00:03:09,070
I would go.

37
00:03:10,000 --> 00:03:11,810
All right, so that works right there.

38
00:03:12,670 --> 00:03:16,660
How would we do the same thing with the ternary in here?

39
00:03:19,540 --> 00:03:25,930
See, this gets a little trickier now that we have else, if so, we're going to have to do some nesting

40
00:03:26,140 --> 00:03:27,760
of some of this ternary.

41
00:03:28,390 --> 00:03:33,820
So first we check the first condition and we see if that's true.

42
00:03:34,900 --> 00:03:36,880
Then here's what we get to say.

43
00:03:37,900 --> 00:03:44,020
If it's false, though, we're going to check for another expression, another ternary.

44
00:03:45,190 --> 00:03:52,570
So we're going to nest another ternary in here, which we could do inferences just so that we can read

45
00:03:52,570 --> 00:03:56,320
this a little bit more easily and we can say

46
00:03:59,710 --> 00:04:03,070
age questionmark.

47
00:04:08,290 --> 00:04:08,950
Cooling.

48
00:04:12,250 --> 00:04:16,150
Console log, oh, we can do to do this one.

49
00:04:18,790 --> 00:04:21,880
Right there and do the calling there.

50
00:04:23,860 --> 00:04:29,350
So this might be a little bit hard to read, but basically what you can do is read it like this.

51
00:04:33,910 --> 00:04:43,420
Is the age over 40, if so, console, I'm now middle aged, if not, is the age thirty three, if so,

52
00:04:43,750 --> 00:04:47,990
Consolo like that's how old I am and if not, I'm still young yet.

53
00:04:48,910 --> 00:04:49,830
Let's give that a shot.

54
00:04:51,730 --> 00:04:53,560
All right, so this worked.

55
00:04:54,520 --> 00:05:01,210
So this is a repeat of that one, and that's in a ternary expression, so you could do it all in a single

56
00:05:01,210 --> 00:05:03,490
line, that would be totally fine.

57
00:05:04,150 --> 00:05:09,310
OK, now for number four, we've got to take our, if else, if else, statement and make it into a

58
00:05:09,310 --> 00:05:10,280
switch statement.

59
00:05:11,110 --> 00:05:15,080
So we're going to take this right here and reimagine this as a switch statement.

60
00:05:15,520 --> 00:05:21,670
Now, if we were to do what we did last time, we would take a switch and then age and then check it

61
00:05:21,670 --> 00:05:27,670
against specific values that wouldn't help us with the range that we need to that we need to deal with.

62
00:05:27,670 --> 00:05:34,390
So this greater than 40, we're going to have to see if this is true instead of just checking for a

63
00:05:34,390 --> 00:05:35,550
specific value.

64
00:05:36,310 --> 00:05:38,760
So let's change this to switch.

65
00:05:38,770 --> 00:05:39,460
True.

66
00:05:40,480 --> 00:05:47,410
And then we can do a case where age is greater than 40

67
00:05:50,320 --> 00:05:55,810
and then log that break.

68
00:05:57,680 --> 00:06:01,730
And then case where age is

69
00:06:04,670 --> 00:06:05,720
thirty three

70
00:06:09,470 --> 00:06:13,400
and then comes a log that in break.

71
00:06:18,020 --> 00:06:22,580
And then default, and that's the same as the statement.

72
00:06:25,480 --> 00:06:27,200
We go right there.

73
00:06:28,430 --> 00:06:33,680
So now if we save that, that'll give us the same behavior there.

74
00:06:35,970 --> 00:06:44,220
Notice these are thirty three, so that accounts for that one, that one and that one, if we make this

75
00:06:44,220 --> 00:06:51,860
thirty two, I'm still young yet if we make this forty five, I'm now middle aged.

76
00:06:51,870 --> 00:06:52,700
Fantastic.

77
00:06:52,860 --> 00:06:58,620
OK, so there's our example of the Section four code challenge and welldone.
