Tell us what’s happening:
Describe your issue in detail here.
in JavaScript Algorithms and Data Structures course in Title Case a Sentence, I wrote the code, but I don’t understand why my code is wrong, it gives you the required from the challenge.
**Your code so far**
function titleCase(str) {
let arr = str.split(" ");
let result = "";
for (let i = 0; i< arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] === arr[i][0])
result += arr[i][j].toUpperCase();
else
result += arr[i][j].toLowerCase();
}
result += " ";
}
return result;
}
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/93.0.4577.82 Safari/537.36
Challenge: Title Case a Sentence
Link to the challenge: