randRange( -5, 5 ) randRange( -5, 5 ) randRange( -5, 5 ) randRange( -5, 5 ) randFromArray( [ "add", "subtract" ] ) ( OPERATION === "add" ? "+" : "-" ) ( OPERATION === "add" ? ( A_REAL + B_REAL ) : ( A_REAL - B_REAL ) ) ( OPERATION === "add" ? ( A_IMAG + B_IMAG ) : ( A_IMAG - B_IMAG ) ) complexNumber(A_REAL, A_IMAG) complexNumber(B_REAL, B_IMAG) "\\color{" + ORANGE + "}{" + A_REP + "}" "\\color{" + BLUE + "}{" + B_REP + "}" "\\color{" + ORANGE + "}{" + A_REAL + "}" "\\color{" + ORANGE + "}{" + A_IMAG + "}" "\\color{" + BLUE + "}{" + B_REAL + "}" "\\color{" + BLUE + "}{" + B_IMAG + "}"

OPERATION == "add" ? "Add" : "Subtract" the following complex numbers:

(A_REP_COLORED) OPERATOR (B_REP_COLORED)

[ ANSWER_REAL, ANSWER_IMAG ]

Complex numbers can be OPERATIONed by separately OPERATIONing their real and imaginary components.

The real components of the two complex numbers are A_REAL and B_REAL, respectively, so the real component of the result will be A_REAL_COLORED OPERATOR \color{BLUE}{negParens(B_REAL)} , which equals ANSWER_REAL.

The imaginary components of the two complex numbers are A_IMAG and B_IMAG, respectively, so the imaginary component of the result will be A_IMAG_COLORED OPERATOR \color{BLUE}{negParens(B_IMAG)} , which equals ANSWER_IMAG.

The result is complexNumber(ANSWER_REAL, ANSWER_IMAG); its real component is ANSWER_REAL and its complex component is ANSWER_IMAG.