use to toggle sign in sequence .
var toggle = 1 ; for ( var i = 0 ; i <= n ; i += 2 ) { ans = ans + nCr [ n ] [ i ] * Math . pow ( cosTheta , n - i ) * Math . pow ( sinTheta , i ) * toggle ; toggle = toggle * - 1 ; } return ans . toFixed ( 1 ) ; }