Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattnwa/b516ee3292a9a8c782e9 to your computer and use it in GitHub Desktop.
Save mattnwa/b516ee3292a9a8c782e9 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mattnwa 's solution for Bonfire: Title Case a Sentence
// Bonfire: Title Case a Sentence
// Author: @mattnwa
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
strLowercase = str.toLowerCase().split(' ');
for (var i =0; i <strLowercase.length; i++){
strLowercase[i] = strLowercase[i].split('');
strLowercase[i][0] = strLowercase[i][0].toUpperCase();
strLowercase[i] = strLowercase[i].join('');
}
return strLowercase.join(' ');
}
titleCase("I'm a little tea pot");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment