I came up with the solution below, and testing it gives me the desired output, but it won’t pass when I submit it. What am I missing? Or am I only supposed to answer according to principal?
**Your code so far**
function titleCase(str) {
let arr = str.split(" ");
let outStr = ""
//console.log(arr)
for (let i = 0; i < arr.length; i++){
let str1 = arr[i].charAt(0).toUpperCase() + arr[i].slice(1).toLowerCase();
//console.log(str1)
outStr += str1 + " ";
}
//console.log(outStr);
return outStr;
}
titleCase("I'm a little tea pot");
titleCase("sHoRt AnD sToUt");
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Link to the challenge: