Having Title Case a Sentence issues

Tell us what’s happening:
Describe your issue in detail here.
so i was coding this and it returns a string with each first letter capitalized but it still gives error any help that i can get??

  **Your code so far**

function titleCase(str) {
str=str.toLowerCase().split(" ");
let newStr="";

for(let i=0;i<str.length;i++){
newStr = newStr + " "+ str[i].charAt(0).toUpperCase()+str[i].slice(1);


return newStr;

titleCase("sHoRt AnD sToUt");
  **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:

If I put this at the bottom:

console.log(`***${titleCase("sHoRt AnD sToUt")}***`);

I get this output:

*** Short And Stout***

Does that make it clear what the issue is?

you mean i am having extra spaces in my code right?

1 Like

Yup, that was my point.

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