My solution worked when I console.log the return value, so why does it fail the tests?
Your code so far
function titleCase(str) {
let strArray = str.split(" ");
let newStr = ""
for (let i = 0; i < strArray.length; i++) {
strArray[i] = strArray[i].toLowerCase();
newStr += strArray[i].slice(0, 1).toUpperCase();
newStr += strArray[i].substring(1) + " ";
}
console.log(newStr);
return newStr;
}
titleCase("I'm a little tea pot");
titleCase("sHoRt AnD sToUt");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Link to the challenge: