1
00:00:00,690 --> 00:00:01,980
Welcome back.

2
00:00:02,009 --> 00:00:06,160
Let me show you how I'm going to solve this one if you're able to.

3
00:00:06,180 --> 00:00:06,890
Got it.

4
00:00:06,900 --> 00:00:08,010
Bravo.

5
00:00:08,039 --> 00:00:09,660
If you're able to try it.

6
00:00:09,690 --> 00:00:10,450
Bravo.

7
00:00:10,480 --> 00:00:11,580
But if you couldn't.

8
00:00:11,610 --> 00:00:12,570
Don't worry.

9
00:00:12,600 --> 00:00:17,550
Sit back and let's see how I'm going to solve this particular challenge.

10
00:00:17,820 --> 00:00:21,210
So the first one is let's start for the first one.

11
00:00:21,210 --> 00:00:22,560
So let's start from here.

12
00:00:23,960 --> 00:00:26,490
So I can see the question and my code.

13
00:00:26,510 --> 00:00:33,620
Well, in programming, there is no one way of doing something.

14
00:00:33,710 --> 00:00:41,600
But at the end of the day, the function should perform the particular task that you want the function

15
00:00:41,600 --> 00:00:42,230
to do.

16
00:00:42,770 --> 00:00:49,310
So the first question is that create a function to find the number of words in a string.

17
00:00:49,340 --> 00:00:57,050
And as we see here as before this, what we are doing here, but instead we are going to make use of

18
00:00:57,050 --> 00:01:04,040
a function because for a function we can re-use it and that will help us avoid repetition of code.

19
00:01:04,400 --> 00:01:11,480
So after I create a function, if I want to find a length of a string, I just pass in the string and

20
00:01:11,480 --> 00:01:12,410
I'm good to go.

21
00:01:12,590 --> 00:01:18,590
So let me show you how I'm going to solve this particular challenge.

22
00:01:18,890 --> 00:01:20,630
So this is how I always do.

23
00:01:20,630 --> 00:01:23,080
I call something brainstorming.

24
00:01:23,090 --> 00:01:25,760
I'm going to brainstorm in this particular question.

25
00:01:25,970 --> 00:01:28,670
One First of all, a function.

26
00:01:28,670 --> 00:01:36,620
Find the words in a string so I can declare or I can start with my function name where we can use function,

27
00:01:36,620 --> 00:01:39,440
expression or statement, whatever.

28
00:01:39,440 --> 00:01:44,300
So let me stick to using the normal function or function expression for the one.

29
00:01:44,300 --> 00:01:48,980
For this one, let's say const or I'm inside the same command here, so.

30
00:01:48,980 --> 00:01:49,420
Okay.

31
00:01:50,400 --> 00:01:52,130
Okay, let me bring this one here.

32
00:01:53,330 --> 00:01:53,800
Like that.

33
00:01:53,810 --> 00:01:54,610
Let me see.

34
00:01:54,620 --> 00:01:55,940
Now we see the question.

35
00:01:55,940 --> 00:01:57,170
I remove the.

36
00:01:57,990 --> 00:01:58,920
Of course then very soon.

37
00:01:58,920 --> 00:01:59,460
Yeah.

38
00:01:59,460 --> 00:02:01,140
So if solution number one.

39
00:02:01,140 --> 00:02:04,890
So here as solution one.

40
00:02:05,770 --> 00:02:06,720
For their first one.

41
00:02:06,730 --> 00:02:12,160
So for this function, I'm going to use function statement as function.

42
00:02:12,160 --> 00:02:14,650
And the name is what string?

43
00:02:15,890 --> 00:02:16,420
LAMB.

44
00:02:16,430 --> 00:02:23,000
The name of your function must depict what you are doing and going to be.

45
00:02:23,030 --> 00:02:26,030
My parentheses and my carry braces.

46
00:02:26,420 --> 00:02:28,810
So I'm done with the first one.

47
00:02:28,820 --> 00:02:33,340
Meaning that the function to find the number of characters.

48
00:02:33,340 --> 00:02:35,570
So the name of my function is now this.

49
00:02:35,870 --> 00:02:37,400
Now back to point number two.

50
00:02:37,760 --> 00:02:43,820
The function should take a string as a number meaning and pass in parameters here.

51
00:02:43,820 --> 00:02:45,860
So I pass in a string.

52
00:02:46,400 --> 00:02:51,560
And next is the function should retain the numbers of words in a string.

53
00:02:51,800 --> 00:02:55,730
So it means that return I'll bring return here and now the returns you do.

54
00:02:55,730 --> 00:02:58,430
What if you find the length of the words?

55
00:02:58,430 --> 00:03:00,470
And remember we have done it here.

56
00:03:00,470 --> 00:03:05,030
So the string dot length and that is it.

57
00:03:05,030 --> 00:03:07,280
So here the string are passing.

58
00:03:07,280 --> 00:03:13,280
Here is what I want to have the method on it called length and that is it.

59
00:03:13,280 --> 00:03:17,120
So here I need to invoke the function.

60
00:03:18,210 --> 00:03:20,650
Or same as calling the function.

61
00:03:20,670 --> 00:03:23,140
And here we go, string length.

62
00:03:23,160 --> 00:03:25,870
I want to find the length of this particular string.

63
00:03:25,890 --> 00:03:30,650
Let's say I want to pass in as I knew what take.

64
00:03:34,100 --> 00:03:35,030
Academy.

65
00:03:36,310 --> 00:03:36,970
Yes.

66
00:03:36,970 --> 00:03:39,010
So now let me comment out.

67
00:03:39,010 --> 00:03:41,290
This one's I don't see some console.log here.

68
00:03:41,650 --> 00:03:42,220
Yeah.

69
00:03:42,220 --> 00:03:48,730
So now my function is not returning something from here, but I aim to save there the results coming

70
00:03:48,730 --> 00:03:52,510
back from this function into a variable so that I can see it here.

71
00:03:52,630 --> 00:03:54,310
So I'm going to assign.

72
00:03:55,390 --> 00:03:59,940
A to a variable called results is equal to that.

73
00:03:59,950 --> 00:04:04,840
So if I console.log the result.

74
00:04:05,290 --> 00:04:10,210
Let's see, I see 17 characters in this particular string.

75
00:04:10,210 --> 00:04:17,620
So now this function is reusable so I can copy the same method here, function here, paste it, handles

76
00:04:17,620 --> 00:04:21,670
it down to find how many are present in this one.

77
00:04:21,670 --> 00:04:23,890
Let me call this one as resource two.

78
00:04:24,070 --> 00:04:30,160
I can paste again and let's see how many characters are found in this particular.

79
00:04:30,160 --> 00:04:34,270
I see three so I can console.log these ones together.

80
00:04:34,420 --> 00:04:37,060
So let me pick this one and this one.

81
00:04:37,060 --> 00:04:41,050
So this one going to be resource two and then three.

82
00:04:41,080 --> 00:04:42,730
See that now it's reusable.

83
00:04:42,730 --> 00:04:45,760
So if I save it, the first function gave me this.

84
00:04:45,760 --> 00:04:48,580
The second one given this and third one gave me this.

85
00:04:48,580 --> 00:04:52,000
That is about this challenge.

86
00:04:52,030 --> 00:04:55,210
The next challenge, who is going to be a little bit challenged?

87
00:04:55,210 --> 00:05:01,240
Is this so now I can remove this one from here because now I'm done with that one.

88
00:05:01,660 --> 00:05:04,990
So let me remove this one, this question here.

89
00:05:05,140 --> 00:05:11,050
So let me paste copy this one to this one and now paste it.

90
00:05:11,440 --> 00:05:14,050
And now let me call it a solution to.

91
00:05:14,790 --> 00:05:16,710
Solution two.

92
00:05:16,740 --> 00:05:18,300
So let's deduce this question.

93
00:05:18,300 --> 00:05:19,920
So let me comment out this one.

94
00:05:20,430 --> 00:05:22,170
Avoid some console login.

95
00:05:22,170 --> 00:05:22,950
Perfect.

96
00:05:23,100 --> 00:05:30,960
So again, create a function to check if a string is longer than a certain number of characters.

97
00:05:30,960 --> 00:05:32,730
So I need to write my function name.

98
00:05:32,730 --> 00:05:36,750
So here I can see that function for this one.

99
00:05:36,750 --> 00:05:39,600
Let me use function expression cast.

100
00:05:39,690 --> 00:05:41,700
Then I will say is.

101
00:05:42,740 --> 00:05:45,560
Is longer than.

102
00:05:46,160 --> 00:05:52,970
And then I'll go to my function and my parentheses and my carry braces.

103
00:05:53,000 --> 00:05:54,980
I'm done with the first one.

104
00:05:55,930 --> 00:05:57,310
The next one is the function.

105
00:05:57,310 --> 00:05:58,930
Should we take two arguments?

106
00:05:58,960 --> 00:06:02,380
The first is the first argument is a strain.

107
00:06:02,380 --> 00:06:05,470
So my first argument here is a string.

108
00:06:05,860 --> 00:06:08,110
And the second argument is a number.

109
00:06:08,420 --> 00:06:10,240
You see, it's a number here.

110
00:06:10,450 --> 00:06:17,110
So the difference between arguments and parameters is that when you say arguments, arguments are the

111
00:06:17,110 --> 00:06:21,640
values we pass into a function or point, invoking or calling.

112
00:06:21,700 --> 00:06:25,390
So looking at this one, let me show you here.

113
00:06:25,690 --> 00:06:26,610
Yeah, this one.

114
00:06:26,620 --> 00:06:28,920
So this is what you call parameter.

115
00:06:28,930 --> 00:06:33,040
And this is what we call the argument we are passing in.

116
00:06:33,070 --> 00:06:37,960
If you pass in one, pass in one parameter and pass in as what?

117
00:06:37,960 --> 00:06:38,940
One argument.

118
00:06:38,950 --> 00:06:46,570
So the blueprint always determine how the blueprint of this particular main parameter, if it is to

119
00:06:46,570 --> 00:06:49,060
you, pass in to parameters or argument here.

120
00:06:49,120 --> 00:06:52,990
So now coming down here, we are done with the first one, second one.

121
00:06:53,320 --> 00:07:00,550
The next step is that the function should return true if the string is longer than the number of characters

122
00:07:00,550 --> 00:07:02,380
and false if it is not.

123
00:07:02,620 --> 00:07:07,450
So as soon as I see Eve, meaning I'm going to use Eve statement.

124
00:07:08,350 --> 00:07:10,150
So here, Eve.

125
00:07:10,180 --> 00:07:10,810
Here.

126
00:07:10,960 --> 00:07:13,990
And now I would take the string on that.

127
00:07:13,990 --> 00:07:16,690
I have met a property called length.

128
00:07:17,120 --> 00:07:21,700
It is more than the number that I want to pass in.

129
00:07:21,820 --> 00:07:24,640
Then please return.

130
00:07:26,020 --> 00:07:26,590
Yes.

131
00:07:26,590 --> 00:07:28,300
Return true meaning?

132
00:07:28,300 --> 00:07:29,080
Yes.

133
00:07:29,110 --> 00:07:31,930
That string is more than that.

134
00:07:31,930 --> 00:07:33,130
But else.

135
00:07:34,860 --> 00:07:38,970
I retain force, meaning the characters.

136
00:07:39,000 --> 00:07:42,810
The length of the string is not more than the one we specify.

137
00:07:42,990 --> 00:07:45,660
So now this function is going to be more flexible.

138
00:07:46,020 --> 00:07:53,190
We can determine how many characters do we need, but for the first one we did is always retain the

139
00:07:53,850 --> 00:07:58,900
the number of I mean, the, the number of characters in that string.

140
00:07:58,950 --> 00:08:00,900
So let me show you here for this one.

141
00:08:00,900 --> 00:08:11,670
So when I say is longer, remember, let's see if we see that look at IntelliSense inside we have is

142
00:08:11,670 --> 00:08:19,140
longer than which is my function name and it tells you some I mean, guidelines.

143
00:08:19,140 --> 00:08:21,660
Here is my parentheses.

144
00:08:21,690 --> 00:08:30,440
First of all, it takes in a string c that not be any str this one any and a number can be any any number

145
00:08:30,450 --> 00:08:33,480
and that will retain boolean true or false.

146
00:08:33,510 --> 00:08:36,299
That's how this function is returning.

147
00:08:36,570 --> 00:08:39,360
So I want to find this character.

148
00:08:39,480 --> 00:08:40,950
Let's say hello.

149
00:08:41,340 --> 00:08:43,080
How many characters are present?

150
00:08:43,080 --> 00:08:43,830
And I want to know.

151
00:08:43,830 --> 00:08:49,800
Determine if this length the two characters in this hello is more than.

152
00:08:50,700 --> 00:08:51,300
Three.

153
00:08:51,330 --> 00:08:53,160
Then you should retain.

154
00:08:53,160 --> 00:08:53,850
True.

155
00:08:53,880 --> 00:08:55,620
So for this one.

156
00:08:56,480 --> 00:08:58,290
What do you think is going to return?

157
00:08:58,310 --> 00:08:59,370
True or false?

158
00:08:59,390 --> 00:09:08,170
Remember here, if the length of the text I pass in, which is this one, if it is more than the number,

159
00:09:08,180 --> 00:09:11,570
this one, which is this one, then it's going to return.

160
00:09:11,570 --> 00:09:12,110
True.

161
00:09:12,230 --> 00:09:17,930
But does this if you count this, I mean string here.

162
00:09:17,930 --> 00:09:18,230
Let's see.

163
00:09:18,230 --> 00:09:22,730
We have one, two, three, four, five is.

164
00:09:23,650 --> 00:09:25,020
More than three.

165
00:09:25,030 --> 00:09:25,420
Right?

166
00:09:25,420 --> 00:09:29,170
So this function here will run when I give me false.

167
00:09:29,170 --> 00:09:31,690
So let's see if I save it.

168
00:09:31,690 --> 00:09:33,520
Now, let me assign.

169
00:09:34,310 --> 00:09:38,870
To a variable called resource for short and none.

170
00:09:39,050 --> 00:09:41,880
If I console.log the results.

171
00:09:41,900 --> 00:09:42,680
Let's see.

172
00:09:43,040 --> 00:09:48,430
It is true because the number this one is more than three.

173
00:09:48,440 --> 00:09:51,070
But if I pass in, let's say 90 characters.

174
00:09:51,080 --> 00:09:52,070
No, this.

175
00:09:52,070 --> 00:09:53,860
This text is no more than 90 characters.

176
00:09:53,870 --> 00:09:54,830
So why is that?

177
00:09:54,860 --> 00:09:55,780
So let's see.

178
00:09:55,790 --> 00:09:57,530
Now I get false.

179
00:09:57,770 --> 00:10:01,490
So you see that this one is more flexible than the previous one.

180
00:10:01,790 --> 00:10:07,070
So that's how we can make use of functions and do some logic to make something happen.

