Title Case a Sentence - Feedback Please

Tell us what’s happening:
So I was wondering why I have to have the match.uppercase() on my replacer function for both the true and false conditions. The code works somehow. The only reason I realized it worked was because I had a console.log showing the string so I could see the changes lol. Anyway I missed or misunderstood something I’m sure so advice is appreciated.
Your code so far

function titleCase(str) {
  //turns string into all lowercase
  str = str.toLowerCase();
  //a regular expression to match the first character in string and the first character after every space
  const regex = /^[\w]|\s[\w]/g;
  //replacer function to take the match character and capitalize it
  function toUps (match, offset){
    return (offset > 0  ? match.toUpperCase() : match.toUpperCase()); 
    }
    //returns modified string with first letter of each word uppercase. 
    return(str.replace(regex, toUps));
  }

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

Thanks, that makes sense, when I was looking into the method the examples all had 3 parameters so I was under the impression I needed the two I was using.

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