Hi everybody!!
I need some explanation about my below code for this challenge. I think I did meet all the criterias to pass this one; unfortuantely, I didn’t. I did try on console, and it’s correct sofar.
Really appreciate for your time and help in advance. Peace!!
My code so far
function titleCase(str) {
var strLowerCase = str.toLowerCase();
var strLowerCaseArr = strLowerCase.split(" ");
var newStr = "";
for (var i = 0; i < strLowerCaseArr.length; i++){
var eachWord = strLowerCaseArr[i];
var eachWordArr = eachWord.split("");
eachWordArr.splice(0, 1, eachWordArr[0].toUpperCase());
var newEachWord = eachWordArr.join("");
newStr += " " + newEachWord;
}
return newStr;
}
console.log(titleCase("I'm a little tea pot"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Link to the challenge: