Check if count of Alphabets and count of Numbers are equal in the given String | Function to count the number of alphabets ; Counter to store the number of alphabets in the string ; Every character in the string is iterated ; To check if the character is an alphabet or not ; Function to count the number of numbers ; Counter to store the number of alphabets in the string ; Every character in the string is iterated ; To check if the character is a digit or not ; Function to check if the count of alphabets is equal to the count of numbers or not ; Driver code
function countOfLetters ( str ) { var letter = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( ( str [ i ] >= ' ' && str [ i ] <= ' ' ) || ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ) letter ++ ; } return letter ; } function countOfNumbers ( str ) { var number = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) number ++ ; } return number ; } function check ( str ) { if ( countOfLetters ( str ) == countOfNumbers ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; check ( str ) ;