Generate the ith term and print it
if ( n == 1 ) { document . write ( a + " " ) ; return ; } if ( n == 2 ) { document . write ( a + " " + b + " " ) ; return ; } document . write ( a + " " + b + " " + c + " " ) ; for ( let i = 4 ; i <= n ; i ++ ) { d = a + b + c ; document . write ( d + " " ) ; a = b ; b = c ; c = d ; } }