Sum of the alphabetical values of the characters of a string | Function to find string score ; Driver code
function strScore ( str , s , n ) { var score = 0 , index = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( str [ i ] == s ) { for ( j = 0 ; j < s . length ; j ++ ) { score += s . charAt ( j ) . charCodeAt ( 0 ) - ( ' ' ) . charCodeAt ( 0 ) + 1 ; } index = i + 1 ; break ; } } score = score * index ; return score ; } str = [ " " , " " , " " , " " , " " ] ; s = " " ; var n = str . length ; var score = strScore ( str , s , n ) ; document . write ( score ) ;