Title Case a Sentence program

Tell us what’s happening:

Basic Algorithm Scripting: Title Case a Sentence

Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.

For the purpose of this exercise, you should also capitalize connecting words like “the” and “of”.

Your code so far

Help me with the code why its not running


function titleCase(str) {
str=str.toLowerCase();
str=str.split(" ");
let k="";
for(let i=0;i<str.length;i++)
{
  let j = str[i].split("");
  j[0]=j[0].toUpperCase();
  j=j.join("");
 
  k+=j+" ";
    }
console.log(k);
return k;
}

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/81.0.4044.129 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

Some meaningful variable names would help readability and debug-ability greatly.

What do the failing tests say?

Hello!

This took me a little bit to see, but I’ve figured out why you are failing the tests.
You need to return I'm A Little Tea Pot, but you are returning I'm A Little Tea Pot . Note the extra space at the end of your string. :slight_smile:

1 Like