Last active
April 5, 2016 02:25
-
-
Save mmloveaa/49b3348fc5d22570888e66a478075baa to your computer and use it in GitHub Desktop.
4-4-Title case- FreeCodeCamp Q3
This file contains hidden or 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
| Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. | |
| For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". | |
| Remember to use Read-Search-Ask if you get stuck. Write your own code. | |
| function titleCase(str) { | |
| var arr = str.split(' '); | |
| var arr1 = []; | |
| for(var i=0 ; i<arr.length; i++){ | |
| arr1.push(arr[i].charAt(0).toUpperCase()+arr[i].slice(1).toLowerCase()); | |
| // console.log('arr1: ',arr1) | |
| // arr[i].charAt(0).toUpperCase() + arr[i].slice(1) | |
| } | |
| return arr1.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