Please tell me were is my mistake

Tell us what’s happening:

Your code so far


function titleCase(str) {
  let tr = str.trim().toLowerCase().split(' '); 
  tr.forEach(items => items.slice(0,1).toUpperCase() + items.slice(1))    
}

console.log(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/74.0.3729.169 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

forEach is not doing what you think it is. You need to use map on tr and assign the result to a new variable which you would ultimately join back together.

To get you started, you would need to return a value. This will make the console.log() return some information

function titleCase(str) {
  let tr = str.trim().toLowerCase().split(' '); 
  tr.forEach(items => items.slice(0,1).toUpperCase() + items.slice(1))  
  return tr  
}

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

Thanks for the help. I just forgot to return the array converted to a string.