Tell us what’s happening:
Referencing past challenges, I didn’t want to use arrays or loops. I thought it needed to be something using expressions ie /\d+/g. I also used the resource link at: Using an inline function that modifies the matched characters, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter
As a beginner to JavaScript, is there any way that this logic would work or could be completed? I could get the sentence to be either entire caps or lowercase, not how to break the code apart into words or spaces (with w or s). Using match, I had to remove the boolean values, I had no idea I needed the “^”, but was testing it out to get a solution with the training material so far and what I could look up. Thank you!
edit: for clarification and I’m also trying to understand Replace’s RegExp a lot better
Your code so far
function titleCase(str) {
function lowerToUpperCase (match, offset, string) {
return (offset > 0, "" ) + match.toLowerCase();
}
//if after a space, capitalize the first letter
return str.replace(/[A-Z]+/g, lowerToUpperCase);
//need to change it to only the first letter & drop the boolean value
//required to turn it into an array to grab the first character??
//return str.charAt(0).toUpperCase(); Capitalize first character
}
titleCase("I'm a little tea pot");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence