Title Case a Sentence my solution not working

Tell us what’s happening:
Well…though my code seems to be working fine when I put any of the test sentence inside the function, for some reason that I have not figured out, when i “run the tests” in order to submit my solution to FCC it is not accepted.

I don’t understand what is that FCC does not accept really as it seems to be working fine when i console.log any sentence.

Your code so far


function titleCase(str) {
str = str.toLowerCase();
let neastr = str.split(" ");
let final = "";

for (let i=0; i < neastr.length; i++){
  
final = final + " " + neastr[i].replace(neastr[i][0], neastr[i].charAt(0).toUpperCase());
 
}
return final;
    
}

titleCase("I'm a little tea pot");
console.log(titleCase("I'm a little tea pot"))


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

here, add these two lines just abode the return statement:

console.log(str.length)
console.log(final.length)
1 Like

It seems that I have a whitespace before the beginning of my final string.

I will try to delete it with and submit the solution.

Thank you very much ieahleen!! Cheers