I did a very similar algorithm in that challenge and also had the same issue. What is happening is that on line 8 you are basically telling the code to add a final white space after your last word, which means that you have one character extra than the string expected.
There are many ways to deal with that last white space that you can find easily.
A look at the challenge help reveals that this solution is far from being the most efficient or the prettiest, but most of the answers to that challenge from FCC are actually quite difficult to get to because a lot of methods we didn’t learn at this stage are involved.
as you can see in line 10 i cut the last char of the string but it didn’t work.
i know my solution is far away from the best one but i studyed just one week.
give me time @ilenia
i don’t understand your suggest : console.log is jus to check before return.
Oh! Damn sorry I read too fast into it. Your code won’t work when the string passed to the function has uppercase letters that aren’t in the first position of each word.
The function as it is only capitalize the first letter of each word. But FCC is testing with strings such as “HERE IS MY HANDLE HERE IS MY SPOUT” which should return the sentence with only the first letter of each word capitalized!
So, you probably need to ensure the string you pass to the function is transformed to lowercase from the start before you apply your capitalization.
In the FCC’s editor, you’ll see all the tests required to pass with the argument it is passing through your function and the result to be expected. If you use another editor to code, it’s a good idea to call for each of these tests so that you can compare your own console with the results expected by FCC
By the way, I was not pointing at the fact that your solution is not good enough, I was on the contrary saying that I had done the same and was comparing it to FCC’s answers which for that particular challenge were mostly using stuff that you would have not studied yet at this stage, which makes them hard to stumble upon on your own. I was in the exact same situation
These are still worth a look once you’ve implemented a solution of your own though!