var a = Number(document.getElementById(\”a\”).value);\nvar b = Number(document.getElementById(\”b\”).value);\nvar c = Number(document.getElementById(\”c\”).value);\nvar discriminant = (b * b) – (4 * a * c);\nvar x1, x2;\nif (discriminant < 0) {\n var realPart = -b / (2 * a);\n var imaginaryPart = Math.sqrt(-discriminant) / (2 * a);\n x1 = realPart + \" + \" + imaginaryPart + \"i\";\n x2 = realPart + \" - \" + imaginaryPart + \"i\";\n document.getElementById(\"result\").innerHTML = \"The equation has two complex roots:\\n\\nx1 = \" + x1 + \"\\nx2 = \" + x2;\n} else if (discriminant === 0) {\n x1 = (-b + Math.sqrt(discriminant)) / (2 * a);\n document.getElementById(\"result\").innerHTML = \"The equation has one real root:\\n\\nx = \" + x1;\n} else {\n x1 = (-b + Math.sqrt(discriminant)) / (2 * a);\n x2 = (-b - Math.sqrt(discriminant)) / (2 * a);\n document.getElementById(\"result\").innerHTML = \"The equation has two distinct real roots:\\n\\nx1 = \" + x1 + \"\\nx2 = \" + x2;\n}"
}
]
}
\n\n
\n\n
\nQuadratic Equation Solver
\n
Use this calculator to solve quadratic equations of the form ax² + bx + c = 0.
\n
\n
\n
\n
\n
\n
\n
Chart showing the quadratic function:
\n\n
\n
\n