I don't know why this solution is invalid for this challenge


function titleCase(str) {
let cadena = str.split(" ");
let pal= "";

for(let i=0; i< cadena.length; i++){

  for(let j=0; j< cadena[i].length; j++){
    if(j === 0){
      pal += cadena[i][j].toUpperCase()
    }else{
      pal += cadena[i][j].toLowerCase()
    }
    
  }
  pal += " "

}

return pal;
}

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


Challenge: Title Case a Sentence

Link to the challenge:

Try

console.log("|---" + titleCase("I'm a little tea pot") + "---|");

Do you see something funny about the output?

Jajajajaja , I wasn’t see the message, before publish the code

That little extra space at the end trips up folks all the time.

Thanks for help !! I’ll bear in mind the ‘space’