Check if n is less than 4 then simply print all values till n
if ( n < 4 ) { document . write ( " " ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( i + " " ) ; document . write ( " " + " " ) ; }