Tell us what’s happening:
It looks to me that the code I’ve written yields the correct answer. But freeCodeCamp is marking it as incorrect. Am I not seeing something? Could someone point out what requirement I’ve missed? I don’t think I have extra spaces at the beginning or end of my output, so I don’t think it’s that. I know there are similar topics already posted, but I didn’t see one that used join(), so I went ahead and made this post.
**Your code so far**
function titleCase(str) {
let lower= str.toLowerCase();
let newArr=[];
let splitStr = lower.split(" ");
for (let i=0; i<splitStr.length; i++){
newArr[i] = splitStr[i][0].toUpperCase();
for (let j = 1; j<splitStr[i].length; j++){
newArr[i]+=splitStr[i][j];
}
}
let newStr = newArr.join(' ');
console.log(newStr);
return str;
}
titleCase("sHoRt AnD sToUt");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: