Tell us what’s happening:
I am solving the following challenge:
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
Why my code is not passing the tests?
Using console.log() shows the correct expected outcome. I have also run it in another online Javascript compiler and it works there as well.
Your code so far
function titleCase(str) {
let arr = str.split(' ');
let s = '';
for (let i = 0; i < arr.length ; i++){
s += arr[i].charAt(0).toUpperCase() + arr[i].slice(1).toLowerCase() + ' ';
}
return s;
}
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/85.0.4183.102 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: