TitleCase sentence

Tell us what’s happening:
Hello Everyone,
looks like i’m completely suck on this algorithm. I was able to split it to an array and changed everything to lowercase but i’m completely suck at this point. I did a loop but it only returns the first letter of the first word as upper case. Any help will be much appreciated.

Thanks,

Ray

Your code so far

function titleCase(str) {
 var array = str.toLowerCase().split(" ");
  var upperCase = [];
  for (var i=0;i<array.length; i++){
    upperCase = array[i][0].toUpperCase();
    return upperCase;
  }
  
}

titleCase("I'm a little tea pot");

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence

I am now able to get the first letter of each word into an array called upperCase. What is the best way to add these back to the original array?

function titleCase(str) {
var array = str.toLowerCase().split(" ");
var upperCase = [];
for (var i=0;i<array.length; i++){
upperCase.push(array[i][0].toUpperCase());
}
return upperCase;
}

titleCase(“I’m a little tea pot”);

I got it working! thank you so much for pointing me in the right direction. Below is the final answer.

function titleCase(str) {
var array = str.toLowerCase().split(" “);
var upperCase = [];
for (var i=0;i<array.length; i++){
upperCase.push((array[i][0].toUpperCase()) + (array[i].slice(1)));
}
return upperCase.join(” ");
}

titleCase(“I’m a little tea pot”);