Title Case a Sentence challenge won't pass

I’ve tested each of the test cases in my function, and each result is identical to the test case result. What is causing this the tests to fail when I run it?

Here’s the code:

function titleCase(str) {
  // regex patterns
  
  
  let eachWordRegex = /(?!'.*')\b[\w']+\b/gi;
  let eachWord = str.match(eachWordRegex);
  let firstLetter = "";
  let otherLetters = "";
  let newArray = [];
  
  for (let i = 0; i < eachWord.length; i++){
   
    firstLetter = eachWord[i].slice(0,1);
    otherLetters = eachWord[i].slice(1);
    newArray.push(firstLetter.toUpperCase() +       otherLetters.toLowerCase());   
  }

let newStr = newArray.join(" ")+"."; 
console.log(newStr);
return newStr;

}

titleCase("sHoRt AnD sToUt");

You are not returning the correct string. Your function should only be changing the case of the words in the original string passed to the function. For some reason, you are adding a period (.) at the end of the final string returned. The test strings passed to the function do not have periods at the end of them.

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