Otherwise print both parts
else { i = 0 ; while ( i <= ans ) { document . write ( str [ i ] ) ; i ++ ; } document . write ( " " + " " ) ; while ( i < n ) { document . write ( str [ i ] ) ; i ++ ; } document . write ( " " + " " ) ; } document . write ( " " + " " ) ; }