Second Degree Equation Calculator

Find x1 & x2 from a, b & c using ax² + bx + c

Result Board

How does it work?

To get the solution to ax² + bx + c we need to solve it with the equation:
-b ± √b² - 4ac2a
To get the two results, we must perform this operation with both + and - (As seen in the result board).

The discriminant of the equation is the sqare root part, or:
b² - 4ac
If this number is negative, then the equation cannot be solved, due to the number becoming imaginary.

In code, we use the function Math.sqrt(num) to take the square root of the discriminant, which we save in a separate variable. After that, we perform the rest of the equation as normal and get both results, which we display on the result board.

Our code ends up looking like this:
disc = ((b * b) - 4 * a * c)
x1 = (-b + Math.sqrt(disc)) / (2 * a)
x2 = (-b - Math.sqrt(disc)) / (2 * a)