Tell us what’s happening:
I think I’m getting the correct output,yet the test cases are not passing.Please help.
Your code so far
function titleCase(str) {
var s=str.toLowerCase();
var s1=s.split(" ");
var r=[];
for(var i=0;i<s1.length;i++){
for(var j=0;j<s1[i].length;j++){
if(j===s1[i].length-1){
if(j===0){r.push(s1[i][j].toUpperCase()+" ");}
else{ r.push(s1[i][j]+" ");}
}
else if(j===0){
r.push(s1[i][j].toUpperCase());
}
else{
r.push(s1[i][j]);
}
}
}
return r.join("");
}
titleCase("sHoRt AnD sToUt");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0.
Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence
