Tell us what’s happening:
My output seem good on terminal but still fail with testcase
Your code so far
function titleCase(str) {
str = str.split(" ");
var test= "";
for (var i = 0; i < str.length; i++){
test += str[i].charAt(0).toUpperCase() + str[i].slice(1).toLowerCase()+ " ";
}
return test;
}
titleCase("I'm a little tea pot AnD jUsT pAssiNG thrOugh");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.
You have a trailing space at the end of the sentence so it does not pass the tests. You could use trim() to remove it. Another option would be to manipulate each word in the str array and then join them afterwards => str.join(' ').
The join function only separates each item. It does not append the separator to the end.