Hi there! I seem to have a problem with my code not being accepted. It seems to be working fine in terms of getting the required output, but it doesn’t seem to be passing the challenge on freeCodeCamp. I’ve added .trim()
to my return output to clear out any whitespace but the issue still persists. Any help would be greatly appreciated!
var strArr = []; // multiple strings in an array
var numberOfStr = 0; // corresponds to number of strings in strArr
var n = 0; // index for individual substrings
function titleCase(str) {
// var substring is the result of converting str to lowercase and splitting it)
for (var substring = str.toLowerCase().split(' '); n < substring.length; n++) {
// substringCase converts the first index of a substring into uppercase
var substringCase = substring[n][0].toUpperCase().concat(substring[n].slice(1));
// makes sure that amount of strings in new array === amount in old array
if (numberOfStr < substring.length) {
numberOfStr = strArr.push(substringCase);
}
}
return strArr.join(" ").trim();
}
titleCase("I'm a little tea pot");