Title Case a Sentence - result ok but still not passed

Title Case a Sentence - result ok but still not passed
0

#1

Tell us what’s happening:

When I am using this piece of code is jsfiddle.net it shows me perfect result. Even in FCC console log its showing correct result for all the testcases but somehow it is not passed, not sure why.

Your code so far

function titleCase(str) {
  
  var words = str.split(' ');
  var ans = "";
  
  for(var i = 0; i < words.length; i++) {
    ans += words[i].charAt(0).toUpperCase() + 
           words[i].substring(1).toLowerCase() + 
           " ";
  }
  
  return ans;
}

titleCase("sHoRt AnD sToUt");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36.

Link to the challenge:


#2

"Short And Stout " is not the correct result, you have an extra space at the end.


#3

Thanks a lot!! Fixed it now :slight_smile:

function titleCase(str) {

var words = str.split(’ ');
var ans = ‘’;

for(var i = 0; i < words.length; i++) {
ans += words[i].charAt(0).toUpperCase() + words[i].substring(1).toLowerCase() ;
if (i < words.length - 1)
ans += ’ ';
}

return ans;
}

titleCase(“sHoRt AnD sToUt”);