Title Case a Sentence: Difficulty passing tests [Solved]

Tell us what’s happening:
I am passing the test cases… so it appears, but there must be something going wrong because I’m not passing this.

Your code so far

function titleCase(str) {
  words = str.split(" ");
  newSentence = [];
  for (i=0; i<words.length; i++) {
    newSentence.push(words[i][0].toUpperCase());
    for (j=1; j<words[i].length; j++) {
      newSentence.push(words[i][j].toLowerCase());
    }
    newSentence.push(" ");
  }
  return newSentence.join("");
}

titleCase("sHoRt AnD sToUt");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:

I guess there is a space after the last word.

1 Like

ahh yes, I’ve just realised that I’m printing one too many spaces! thanks