First letter of each word capitalized

Hello

I’m trying to setle the “Title Case a Sentence” algorithm
but something wrong :frowning:
I must capitalize every first leter of words in the string
here is my solution I comment every string what I’m doing
What I’m doing wrong when I’m trying to convert to the toUpperCase()

 <p>
function titleCase(str) {
  var convertToLower = '';
  var stringSplit = ''; //split string to word array
  var stringWordSplit = ''; //split word to letter array
  var toUpper = []; //var for convert first latter of word
  
  convertToLower = str.toLowerCase(); // converting all leters to the low case  
  stringSplit = convertToLower.split(" "); //spliting str string to the single words 
  
  for(var i = 0; i < stringSplit.length; i++){
    
    // every words from str string splitting to the single letter
    stringWordSplit = stringSplit[0].split('');   
    
    for(var j = 0; j < stringWordSplit.length; j++){ 
      // convert first letter of stringWordSplit array to the Upper case
      //and here something wrong 
      toUpper += stringWordSplit[0].toUpperCase();
    }
  }
    
  
  return toUpper;
}

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

</p>

toUpper is an array, and you’re trying to concat using += like it’s a string.

Defining fewer variables and better naming of the ones you do need would help you avoid these issues.