Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function solve_quadratic(a, b, c) {
    var d = (Math.pow(b, 2) - (4 * a * c));
    var x1 = (-b + Math.sqrt(d)) / (2 * a);
    var x2 = (-b - Math.sqrt(d)) / (2 * a);
    if (d > 0) {
        x1 = (-b - Math.sqrt(d)) / (2 * a);
        x2 = (-b + Math.sqrt(d)) / (2 * a);
        console.log("x1 = " + x1 + "\nx2 = " + x2);
    }
    if (d === 0) {
        x1 = (-b) / (2 * a);
        console.log("X = " + x1);
    }
    if (d < 0) {
        console.log("No real roots");
    }
}
solve_quadratic(2, 5, -3);
console.log();
solve_quadratic(2, -4, 2);
console.log();
solve_quadratic(4, 2, 1);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers