Tell us what’s happening:
Cannot understand why the function is wrong Assigment - Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. For the purpose of this exercise, you should also capitalize connecting words like “the” and “of”.
Your code so far
function titleCase(str) {
let newStr = “”;
const strArr = str.split(" ");
for(let i = 0; i < strArr.length; i++){
let subStr = strArr[i].toLowerCase();
let tStr = subStr.replace(subStr.charAt(0) ,subStr.charAt(0).toUpperCase() )
newStr+= tStr + " ";
}
console.log(newStr)
return newStr;
}
titleCase(“I’m a little tea pot”);
function titleCase(str) {
let newStr = "";
const strArr = str.split(" ");
for(let i = 0; i < strArr.length; i++){
let subStr = strArr[i].toLowerCase();
let tStr = subStr.replace(subStr.charAt(0) ,subStr.charAt(0).toUpperCase() )
newStr+= tStr + " ";
}
console.log(newStr)
return newStr;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: