Quantcast
Viewing latest article 2
Browse Latest Browse All 50

freeCodeCamp Challenge Guide: Title Case a Sentence

My approach on this challenge:

function titleCase(str) {

var arr = [];

var upperCase;
var lowerCase = str.toLowerCase();

var words = lowerCase.split(’ ');//array of lowerCase words

for(var i = 0;i < words.length;i++) {
upperCase = words[i][0].toUpperCase() + words[i].substr(1);

arr.push(upperCase);

str = arr;

}

str = str.join(" ");

return str;
}

titleCase(“I’m a little tea pot”);

Read full topic


Viewing latest article 2
Browse Latest Browse All 50