Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piqueen314/83fd8033fb3ec99778b0 to your computer and use it in GitHub Desktop.
Save piqueen314/83fd8033fb3ec99778b0 to your computer and use it in GitHub Desktop.
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
// Bonfire: Title Case a Sentence
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
var words=str.split(" ");
for(var i=0; i<words.length; i++)
{
words[i]=words[i].toLowerCase();
words[i]=words[i].charAt(0).toUpperCase()+ words[i].slice(1);
}
str= words.join(" ");
return str;
}
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