Created
July 16, 2015 19:03
-
-
Save luisangelma/cded0621ba72ff104048 to your computer and use it in GitHub Desktop.
Vowels and Consonants
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
| function getVowels(str) { | |
| var numberOfVowels = 0; | |
| var strArray = str.split(''); | |
| for (var i = 0; i < strArray.length; i++ ) { | |
| switch(strArray[i]) { | |
| case 'a': | |
| numberOfVowels++; | |
| break; | |
| case 'e': | |
| numberOfVowels++; | |
| break; | |
| case 'i': | |
| numberOfVowels++; | |
| break; | |
| case 'o': | |
| numberOfVowels++; | |
| break; | |
| case 'u': | |
| numberOfVowels++; | |
| break; | |
| } | |
| } | |
| console.log('The total number of vowels is: ' + numberOfVowels); | |
| } | |
| function getConsonants(str) { | |
| var numberOfConsonants = 0; | |
| for (var i = 0; i < str.length; i++ ) { | |
| if (str.charAt(i) === 'a' || str.charAt(i) === 'e' || str.charAt(i) === 'i' || str.charAt(i) === 'o' || str.charAt(i) === 'u' || str.charAt(i) === ' ') { | |
| numberOfConsonants; | |
| } else { | |
| numberOfConsonants++; | |
| } | |
| } | |
| console.log('The total number of consonants is: ' + numberOfConsonants); | |
| } | |
| getVowels('coding campus'); | |
| getConsonants('coding campus'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment