Forked from anonymous/bonfire-title-case-a-sentence.js
Created
December 4, 2015 04:47
-
-
Save robertsheacole/9dac0e50239a148536db to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/robertsheacole 's solution for Bonfire: Title Case a Sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bonfire: Title Case a Sentence | |
// Author: @robertsheacole | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function titleCase(str) { | |
//make string lowercase and split into array | |
var makeArray = str.toLowerCase().split(' '); | |
//loop through array | |
for ( var i = 0; i < makeArray.length; i++){ | |
//set each string's first letter to uppercase and concat rest of word to the first letter | |
makeArray[i] = makeArray[i].charAt(0).toUpperCase() + makeArray[i].substring(1); | |
} | |
//back to string with spaces | |
return makeArray.join(' '); | |
} | |
console.log(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