This "if (answer += i * x)" is not correct because the result of the expression is not a boolean.

Instead of this statement you can put "answer += Math.pow(x, i);"