Let’s break down your code using the test case:
So, your str looks like this in beginning:
In first step, you convert your str to lowercase.
Now, str looks like : "i'm a little tea pot"
Then you split the str into an array:
Now, str looks like:
["i'm","a","little","tea","pot"]
After you use the loops you are changing the ithe element of str to its first character in uppercase.
For example: "i'm" changes to I "little" changes to L and so on
And str looks like:
["I","A","L","T","P"]
That means you having only first character and rest of the string is gone.
Try solving now.
Try to figure out how you will get full strings instead of first character.