Tell us what’s happening:
My code returns a string with each word capitalized, however all the tests fail. I do not see an extra space anywhere.
What might be going on here?
Thank you!
Your code so far
let result = [];
function titleCase(str) {
str = str.split(' ');
for (let i = 0; i < str.length; i++){
result.push(str[i].charAt(0).toUpperCase() + str[i].slice(1).toLowerCase());
}
result = result.join(" ");
return result;
}
titleCase("sHoRt AnD sToUt");
console.log(result);
console.log(typeof result);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0
.
Challenge: Title Case a Sentence
Link to the challenge: