You might also get a task to convert your story into a title case, and actually it may be tricky.
This is why it is really good that he never got provided test cases.
So actually, we must build a function title case, and when we're providing insight, I'm a little
teapot.
We should return string and it should be capitalized.
And as you can see, every single word here is capitalized.
Not only the first word it, and this is important.
Also, it doesn't matter how we provide our string, it must be capitalized correctly.
So let's build dysfunction now.
And actually, again, we have two possibilities here.
We can use for loop over can use native JavaScript methods.
So first of all, illustrated by using follow up.
So here work great entitled case method and we're getting string as an argument.
And first of all, we want to create energy.
So we have every single character here so we can right here that our stream equals stream to lowercase
split and here will be one space.
So actually, here we are writing array inside string.
And actually, I am writing code like this because I want to show you how you should not write your
coat.
And it's not just about logic here that we're using for loop, but regarding what you are doing.
As you can see, first of all, the bad practice here is to use the same argument like we have here
without our argument inside, which means, first of all, we might modified.
Yes, it's not the case with the string, but it will be like this with the race object because when
we're defining a reference.
Secondly, here we're getting back in the.
But here we're writing it in so string, which makes it confusing.
And both these things you must not do in your code or in interview, because with this, you are showing
that you are right in that code.
So much better approach here will be to create additional property array or whatever you want.
And here we're getting three to lowercase split and we're totally fine.
After this, we must write for a loop.
So here we can just write plain native loop, which I also don't advise.
So here we can write.
Our eye equals zero I less than three in length and here I plus.
And of course, here is not strain, but our array.
So here inside now we can mutate every single element so we can right here.
Every eye equals.
And here we have the same element dot character at zero.
And actually what it does, it takes the first element of our string.
In our case, every single element of our array is a string.
And here we're getting the first letter so we can capitalize it and was this way right into uppercase,
which is also a native method inside JavaScript.
And here we can write array eye dot slice one.
And in this case, we're getting all our elements of the string except of the first letter.
This is what we want.
We want to capitalize the first letter and then just take all the letters.
And after this, we can simply join our array.
So we're right here, return array join and we're joined in and by space.
Now we can write here.
Console.log were Colin here title case and were provided inside our string.
I'm a little teapot.
Let's check if it's working.
I'm deployed in the page and we're getting I'm a little teapot, which actually looks fine and we solved
the task.
But first of all, we just hibernate before.
And as I previously said, it's not the best approach if, well, living through every single element
of the array.
At least you must use for reach for rain and not native fauna.
Then your code will be better.
Second thing that they don't like here is that we are overriding every single element of our right,
which actually means we're not creating the tree, but we're overriding the previous one.
And it is also not the best approach.
This is why let's write this whole code just by using plain JavaScript methods, because actually here
we don't even need for a loop at all.
So what I want to do here, I want to take our string and I want to convert it to lowercase.
This was totally fine.
After this, we want to split it with space.
This was also totally fine.
But after this, we can use map because essentially what we are doing here is a map.
We want to change every single element inside our rate.
This is where I am Colin Map, and we're getting our board.
And actually, as you can see, it is more clear now because we're using property world and not some
eye or array where we don't know what we're talking about.
And here we want to do exactly the same word dot character at zero.
So we're getting the first element here.
We're using two upper keys and here we're using plus and we're taking all other letters with four dots
lies.
And here is one.
And as you can see, this code is essentially the same.
We didn't change it, but it is much more efficient, easier to read, and it shows that you are more
advanced developer because here we are not using for loop, but map, which is not that difficult.
And here we are, just returning for every single word in your word.
And it is important here to mention that character, ed and slice are not mutating functions, which
means we're getting new strain and we didn't mutate old strain.
Let's check this out Amber Alert in this page, and we're getting our array with capitalized strings,
which means I forgot at the end to make our giant.
So here we can simply call our Joan with space inside.
Let's check this out, and we're getting exactly the same string.
So I highly recommend you unintuitive to what's your name and to check that your data types are matched
with your names.
And make your code easier to read if it is possible.