Title Case a Sentence Issues

Tell us what’s happening:

Hello Community! I have been resolving this challenge and I am having a bug! Can you tell me where is my Problem! Thanks in advance!

Your code so far

function titleCase(str) {

//split string to array
let splitString = str.split(" ");

//loop through the array
for(let i = 0; i < splitString.length; i++){

    //turn the first letter into upperCase
    let upperCase = splitString[i][0].toUpperCase();

    //turn all the word into LowerCase
    let lowerCase = splitString[i].toLowerCase();

    //replace the {lowerCase} first letter to the {upperCase};
    let word = lowerCase.replace(splitString[i], upperCase);
    //error? why is not returning the {word}

**Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

you dont provide the right arguments to the replace() method. Its first parameter is the thing you want to replace and the second the thing you will put in its place.
Your line tells the following- take the word in lower case(lowerCase), find the actual word(splitString[i]) and replace it with its first letter in upper case(upperCase). For the word “HERE” you try to find “HERE” in the string “here” and put “H” in its place. It cant find such thing in the first place and even if it did, it would put a single letter on its place.
To make replace do what you want, you must pass the first letter of the word in lower case, so it finds that letter and put the same letter in upper case


@Sylvant Thank you ! for the explanation! I will fix it out!

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