Program to count vowels , consonant , digits and special characters in string . | Function to count number of vowels , consonant , digitsand special character in a string . ; Declare the variable vowels , consonant , digit and special characters ; str . length ( ) function to count number of character in given string . ; To handle upper case letters ; Driver function .
function countCharacterType ( str ) { var vowels = 0 , consonant = 0 , specialChar = 0 , digit = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { var ch = str [ i ] ; if ( ( ch >= " " && ch <= " " ) || ( ch >= " " && ch <= " " ) ) { ch = ch . toLowerCase ( ) ; if ( ch == " " ch == " " ch == " " ch == " " ch == " " ) vowels ++ ; else consonant ++ ; } else if ( ch >= " " && ch <= " " ) digit ++ ; else specialChar ++ ; } document . write ( " " + vowels + " " ) ; document . write ( " " + consonant + " " ) ; document . write ( " " + digit + " " ) ; document . write ( " " + specialChar + " " ) ; } var str = " " ; countCharacterType ( str ) ;