Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

Tell us what’s happening:
When I am testing my code it works fine, but when I put it into FCC code area and run it returned right answer but wouldn’t submit the task.

Your code so far


function titleCase(str) {
let newStr = str.toLowerCase();
let finalStr = "";
let strArr = newStr.split(" ");
for(let i = 0; i < strArr.length; i++){
  let st = strArr[i].replace(strArr[i][0], function(x) {return x.toUpperCase();}); 
  finalStr += st + " "; 
 
} 
 return finalStr; 
}

console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/83.0.4103.61 Chrome/83.0.4103.61 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

Your answer may look right, but if you look a lot closer, at the very end of the modified string, there is a whitespace. That is causing the challenge to fail.
Here Is My Handle Here Is My Spout If you look at here carefully

2 Likes