Tell us what’s happening:
My code works for all test cases in VSCode but the test cases are not passing. There are no extra spaces being added to the beginning nor end and the strings returned are exactly as they display in the test cases.
titleCase("I'm a little tea pot")
should return the string I'm A Little Tea Pot
.
titleCase("sHoRt AnD sToUt")
should return the string Short And Stout
.
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
should return the string Here Is My Handle Here Is My Spout
.
**Your code so far**
function titleCase(str) {
let strArr = str.split(" ");
for (let i = 0; i < strArr.length; i++) {
strArr[i] = strArr[i][0].toUpperCase() + strArr[i].substring(1).toLowerCase;
}
str = strArr.join(" ");
return str;
}
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/89.0.4389.128 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: