Fill the grid in any possible way
let h = " " ; for ( let i = 0 ; i < m ; i ++ ) { a [ 0 ] [ i ] = h ; if ( h == " " ) { h = " " ; } else { h = " " ; } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( i - 1 < 0 ) { continue ; } if ( a [ i - 1 ] [ j ] == " " ) { a [ i ] [ j ] = " " ; } else { a [ i ] [ j ] = " " ; } } } flag = true ; } if ( ! flag ) { document . write ( " " ) ; } else { document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { document . write ( a [ i ] [ j ] ) ; } document . write ( " " ) ; } } }