My code works, why is it not accepting?

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:

I’m surprised that you say it works in VS Code, because this is invalid JavaScript:

strArr[i] = strArr[i][0].toUpperCase() + strArr[i].substring(1).toLowerCase;

You’re correctly calling toUpperCase() (with parenthesis), but forgot to add them after toLowerCase.

2 Likes

Oh boy… That was it. Thank you. I spent so much time going line by line to see if I made any typos or missed anything and didn’t see that. In VSCode I did have toLowerCase(), which is why it was working. facepalm

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