Program to print a Hollow Triangle inside a Triangle | Function to print the pattern ; Loop for rows ; Loop for column ; For printing equal sides of outer triangle ; For printing equal sides of inner triangle ; For printing base of both triangle ; For spacing between the triangle ; Driver Code
function printPattern ( n ) { var i , j ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j < 2 * n ; j ++ ) { if ( j == n - i + 1 j == n + i - 1 ) { document . write ( " " ) ; } else if ( i >= 4 && i <= n - 4 && ( j == n - i + 4 j == n + i - 4 ) ) { document . write ( " " ) ; } else if ( i == n || ( i == n - 4 && j >= n - ( n - 2 * 4 ) && j <= n + n - 2 * 4 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; document . write ( " " ) ; } } document . write ( " " ) ; } } var N = 9 ; printPattern ( N ) ;