Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Why cannae I pass the tests? I check the returns and they are the same the tests’ desire

Your code so far

function titleCase(minuman) {
   let makanan = minuman.toLowerCase();
   let str = makanan.split(" ");
   let sentence = "";

   for(let i = 0; i < str.length; i++){
     let word = [];

     for(let j = 0; j < str[i].length; j++){
       if(j == 0){
         word.push(str[i][j].toUpperCase())
       }else{
         word.push(str[i][j])
       }
     }
     
     sentence += word.join("")+" ";
     word = [];
   }
  return sentence;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

This line of code ends up adding an extra space at the end of each sentence.

ohh yeah, you’re right. thank you.