Title Case a Sentence

Can someone tell me why the below code is not passing the tests?
function titleCase(str) {
let words = str.split(’ ');
let result = ‘’;
//console.log(words);
for (let i = 0; i<words.length; i++){
let firstStr = (words[i].slice(0,1)).toUpperCase();
let restOfStr = (words[i].slice(1,words[i].length)).toLowerCase();
result += (firstStr + restOfStr + ’ ')
}
//console.log(result)

return result;
}

titleCase(“I’m a little tea pot”);

Please post a link to the challenge.

Sorry

Can you check to see if you are producing an extra space at the end?
(In the log statement print out a character at the beginning and end to catch any unexpected spaces in the result)

You right, there is a space at the end…

Thank you

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.