Print string of odd length in ' X ' format | javascript program to print the given pattern Function to print the given string in respective pattern ; Print characters at corresponding places satisfying the two conditions ; Print blank space at rest of places ; Driver code
function printPattern ( str , len ) { for ( var i = 0 ; i < len ; i ++ ) { for ( var j = 0 ; j < len ; j ++ ) { if ( ( i == j ) || ( i + j == len - 1 ) ) document . write ( str . charAt ( j ) ) ; else document . write ( " " ) ; } document . write ( ' ' ) ; } } var str = " " ; var len = str . length ; printPattern ( str , len ) ;