Welcome back.
Let me show you how I'm going to solve this one if you're able to.
Got it.
Bravo.
If you're able to try it.
Bravo.
But if you couldn't.
Don't worry.
Sit back and let's see how I'm going to solve this particular challenge.
So the first one is let's start for the first one.
So let's start from here.
So I can see the question and my code.
Well, in programming, there is no one way of doing something.
But at the end of the day, the function should perform the particular task that you want the function
to do.
So the first question is that create a function to find the number of words in a string.
And as we see here as before this, what we are doing here, but instead we are going to make use of
a function because for a function we can re-use it and that will help us avoid repetition of code.
So after I create a function, if I want to find a length of a string, I just pass in the string and
I'm good to go.
So let me show you how I'm going to solve this particular challenge.
So this is how I always do.
I call something brainstorming.
I'm going to brainstorm in this particular question.
One First of all, a function.
Find the words in a string so I can declare or I can start with my function name where we can use function,
expression or statement, whatever.
So let me stick to using the normal function or function expression for the one.
For this one, let's say const or I'm inside the same command here, so.
Okay.
Okay, let me bring this one here.
Like that.
Let me see.
Now we see the question.
I remove the.
Of course then very soon.
Yeah.
So if solution number one.
So here as solution one.
For their first one.
So for this function, I'm going to use function statement as function.
And the name is what string?
LAMB.
The name of your function must depict what you are doing and going to be.
My parentheses and my carry braces.
So I'm done with the first one.
Meaning that the function to find the number of characters.
So the name of my function is now this.
Now back to point number two.
The function should take a string as a number meaning and pass in parameters here.
So I pass in a string.
And next is the function should retain the numbers of words in a string.
So it means that return I'll bring return here and now the returns you do.
What if you find the length of the words?
And remember we have done it here.
So the string dot length and that is it.
So here the string are passing.
Here is what I want to have the method on it called length and that is it.
So here I need to invoke the function.
Or same as calling the function.
And here we go, string length.
I want to find the length of this particular string.
Let's say I want to pass in as I knew what take.
Academy.
Yes.
So now let me comment out.
This one's I don't see some console.log here.
Yeah.
So now my function is not returning something from here, but I aim to save there the results coming
back from this function into a variable so that I can see it here.
So I'm going to assign.
A to a variable called results is equal to that.
So if I console.log the result.
Let's see, I see 17 characters in this particular string.
So now this function is reusable so I can copy the same method here, function here, paste it, handles
it down to find how many are present in this one.
Let me call this one as resource two.
I can paste again and let's see how many characters are found in this particular.
I see three so I can console.log these ones together.
So let me pick this one and this one.
So this one going to be resource two and then three.
See that now it's reusable.
So if I save it, the first function gave me this.
The second one given this and third one gave me this.
That is about this challenge.
The next challenge, who is going to be a little bit challenged?
Is this so now I can remove this one from here because now I'm done with that one.
So let me remove this one, this question here.
So let me paste copy this one to this one and now paste it.
And now let me call it a solution to.
Solution two.
So let's deduce this question.
So let me comment out this one.
Avoid some console login.
Perfect.
So again, create a function to check if a string is longer than a certain number of characters.
So I need to write my function name.
So here I can see that function for this one.
Let me use function expression cast.
Then I will say is.
Is longer than.
And then I'll go to my function and my parentheses and my carry braces.
I'm done with the first one.
The next one is the function.
Should we take two arguments?
The first is the first argument is a strain.
So my first argument here is a string.
And the second argument is a number.
You see, it's a number here.
So the difference between arguments and parameters is that when you say arguments, arguments are the
values we pass into a function or point, invoking or calling.
So looking at this one, let me show you here.
Yeah, this one.
So this is what you call parameter.
And this is what we call the argument we are passing in.
If you pass in one, pass in one parameter and pass in as what?
One argument.
So the blueprint always determine how the blueprint of this particular main parameter, if it is to
you, pass in to parameters or argument here.
So now coming down here, we are done with the first one, second one.
The next step is that the function should return true if the string is longer than the number of characters
and false if it is not.
So as soon as I see Eve, meaning I'm going to use Eve statement.
So here, Eve.
Here.
And now I would take the string on that.
I have met a property called length.
It is more than the number that I want to pass in.
Then please return.
Yes.
Return true meaning?
Yes.
That string is more than that.
But else.
I retain force, meaning the characters.
The length of the string is not more than the one we specify.
So now this function is going to be more flexible.
We can determine how many characters do we need, but for the first one we did is always retain the
the number of I mean, the, the number of characters in that string.
So let me show you here for this one.
So when I say is longer, remember, let's see if we see that look at IntelliSense inside we have is
longer than which is my function name and it tells you some I mean, guidelines.
Here is my parentheses.
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
and that will retain boolean true or false.
That's how this function is returning.
So I want to find this character.
Let's say hello.
How many characters are present?
And I want to know.
Determine if this length the two characters in this hello is more than.
Three.
Then you should retain.
True.
So for this one.
What do you think is going to return?
True or false?
Remember here, if the length of the text I pass in, which is this one, if it is more than the number,
this one, which is this one, then it's going to return.
True.
But does this if you count this, I mean string here.
Let's see.
We have one, two, three, four, five is.
More than three.
Right?
So this function here will run when I give me false.
So let's see if I save it.
Now, let me assign.
To a variable called resource for short and none.
If I console.log the results.
Let's see.
It is true because the number this one is more than three.
But if I pass in, let's say 90 characters.
No, this.
This text is no more than 90 characters.
So why is that?
So let's see.
Now I get false.
So you see that this one is more flexible than the previous one.
So that's how we can make use of functions and do some logic to make something happen.