Why does it not accept my code?

Tell us what’s happening:
Describe your issue in detail here.
When I test my code with the sample text, it returns the correct text. Why won’t it accept my answer as correct? Nevermind…I added an extra space at the end.

   **Your code so far**

function titleCase(str) {
 let text = str.split(/\s/);
 let words = [];
 let go = "";
 let final = "";
 for (let i = 0; i < text.length; i++) {
   words = text[i][0].toUpperCase() + text[i].slice(1).toLowerCase();
final = final + words + " ";
 return final;

titleCase("I'm a little tea pot");
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

You are adding extra spaces. Try

console.log("***" + titleCase("I'm a little tea pot")  + "***");
1 Like

Sorry, I noticed as you were typing. I corrected it. Thank you so much for responding so quickly!

1 Like

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