Count consonants in a string ( Iterative and recursive methods ) | Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code
function isConsonant ( ch ) { ch = ch . toUpperCase ( ) ; console . log ( ch ) ; return ( ! ( ch == " " ch == " " ch == " " ch == " " ch == " " ) && ch . match ( / [A-Z] / i ) ) ; } function totalConsonants ( str ) { var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) if ( isConsonant ( str [ i ] ) ) ++ count ; return count ; } var str = " " ; document . write ( totalConsonants ( str ) ) ;