Title Case a Sentence [ help ] Messy code

Tell us what’s happening:
I know the code i wrote is long winded and inefficient but i don’t see why it doesn’t work.
It outputs the sentence with the first letter in each word in caps and ends with the period. I don’t see why it doesn’t fulfill the requirements to pass

I am unable to put a link but here the title of the challenge
Title Case a Sentence
Your code so far


function titleCase(str) {
  var array = str.split(" ");
  var result = "";
  for (let i=0; i<array.length; i++){
    var low = array[i].toLowerCase();
    var up = array[i].toUpperCase();
    var firstup = up.substring(0,1);
    var lastdown = low.substring(1,low.length);
    var finalstring = firstup+lastdown;
    array[i] = finalstring;
  }
  var result = (array.join(" ")+ ".");
  return result;
}

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/71.0.3578.98 Safari/537.36.

Link to the challenge:

But it shuldn’t (notice that in test cases period is not the same color as the return string).

1 Like

oh! man I’ve been staring at it for like 30 minutes. Thanks for pointing it out. I need to get my eyes checked