# Basic Algorithm Scripting: Title Case a SentencePassed

Tell us what’s happening:
Hey everybody,
I am on Basic Algorithm Scripting: Title Case a Sentence.
I don’t understand why the I of little is not a lowercase.
Someone can help me with that please ?
Thanks

``````
function titleCase(str) {
let strSplitted = str.split('');
let result = "";

const strSplittedLowerCase = strSplitted.map( letters => { return letters.toLowerCase()});

for(let i=0 ; i<strSplittedLowerCase.length ; i++){
//console.log(strSplitted[i].toUpperCase())
if(strSplittedLowerCase[i-1] === ' ' || strSplittedLowerCase[i] === strSplittedLowerCase[0]){
result += strSplittedLowerCase[i].toUpperCase()
}else{
result += strSplittedLowerCase[i]
}
}
return result;
}

console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt"))
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36`.

Challenge: Title Case a Sentence

Hi PenPen,

this sub-condition causes the trouble:

``````strSplittedLowerCase[i] === strSplittedLowerCase[0]
``````

It compares each lower case character to the first character, which just happens to be an “i” in the test case “I’m a little tea pot”.

Since your first sub-condition `strSplittedLowerCase[i-1] === ' '` makes sure all characters preceded by a space character get capitalized, all you need as the second part of the condition is “OR it is the first character”

Like:

``````if(strSplittedLowerCase[i-1] === ' ' || /* it is the first character */) {
``````
1 Like

Hi michaelsndr,