Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
What Should i add in the code so that it logs out the last two options coreectly!.

Your code so far

function titleCase(str) {
  //what should i add in this code here 
  const words = str.split(" ");
  for (let i = 0; i < words.length; i++){
    words[i] = words[i][0].toUpperCase() + words[i].slice(1);
  }
  return words.join(" ");
}

console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt")) //I want this to return "Short And Stout" 
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")) //This to return "Here Is My Handle Here Is My Stout"

Your browser information:

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

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.