Count strings with consonants and vowels at alternate position | Function to find the count of strings ; Variable to store the final result ; Loop iterating through string ; If ' $ ' is present at the even position in the string ; ' sum ' is multiplied by 21 ; If ' $ ' is present at the odd position in the string ; ' sum ' is multiplied by 5 ; Let the string ' str ' be s$$e$ ; Print result
function countStrings ( s ) { let sum = 1 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( i % 2 == 0 && s [ i ] == ' ' ) sum *= 21 ; else if ( s [ i ] == ' ' ) sum *= 5 ; } return sum ; } let str = " " ; document . write ( countStrings ( str ) ) ;