Quantcast
Viewing all articles
Browse latest Browse all 50

freeCodeCamp Challenge Guide: Title Case a Sentence

@pouccini wrote:

Can anyone tell me why this code does not complete the challenge? I can’t seem to find the problem. It looks like it returns the right answer.

var fullStr = “”;
function titleCase(str) {
str = str.toLowerCase().split(" “);
for (var i = 0; i < str.length; i++){
var capitalize = str[i].substring(0,1).toUpperCase();
var loseFirst = str[i].substr(1);
fullStr = fullStr + capitalize + loseFirst +” ";
}
return fullStr.substring(0, fullStr.length -1);
}

titleCase(“sHoRt AnD sToUt”);

Read full topic


Viewing all articles
Browse latest Browse all 50