Why is my code not accepted? The output matches the requirements

Tell us what’s happening:
I have used two for loop’s instead of one for loop and other in-built functions like the solutions suggest. Does it not get accepted because of inefficiency maybe?

  **Your code so far**

function titleCase(str) {
let strArr = str.split(" ");
let finalStr = "";
for (let i = 0; i < strArr.length; i++) {
  let tempArr = strArr[i].split("");
  var tempStr= "";
  for (let j = 0; j < tempArr.length; j++) {
    if (j == 0) {
      tempStr += tempArr[j].toUpperCase();
    }
    else tempStr +=tempArr[j].toLowerCase();
  }
  finalStr += tempStr + " ";
}
return finalStr;
}

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/92.0.4515.131 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

Are you sure it matches? I might suggest you look at what you can’t see. I think you have one space too many…at the end of the string.

Lmao… I feel so dumb now… Thank you! :upside_down_face:

1 Like

Please don’t feel like that, we all have done it. Likely more than once. That you saw it and were able to understand how to fix it? Very well done!

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.