Vordar Posted May 13, 2015 Posted May 13, 2015 Hi. I am working on a quadratic formula solver, just for fun. Here is the code I need fixed: var $a, $b, $c, $d, $e, $f, $g, $h, $$A, $$B, a, b, c; function solve(x, y, z) { a = document.getElementById("A_").value; b = document.getElementById("B_").value; c = document.getElementById("C_").value; $a = (-1 * B)/>; $b = (2 * a); $c = Math.pow(b, 2); $d = (4 * a * c); $e = ($c - $d); if ($e >= 0) { $f = Math.sqrt($e); $g = ($a + $f); $h = ($a - $f); $$A = ($g / $B)/>; $$B = ($h / $B)/>; if ($$A == $$B)/> { return $$A; } else if (Math.abs($$B)/> == $$A) { return "± " + $$A; } else { return $$A + " or " + $$B; } else { return "I'm sorry, this calculator can not compute imaginary solutions."; } Apparently, I am misusing the brackets, parentheses, etc. I have a version that works: function solve(x, y, z) { a = document.getElementById("A_").value; b = document.getElementById("B_").value; c = document.getElementById("C_").value; $a = (-1 * B)/>; $b = (2 * a); $c = Math.pow(b, 2); $d = (4 * a * c); $e = ($c - $d); if ($e >= 0) { $f = Math.sqrt($e); $g = ($a + $f); $h = ($a - $f); $$A = ($g / $B)/>; $$B = ($h / $B)/>; if ($$A == $$B)/> { return $$A; } else { return $$A + " or " + $$B; } } else { return "I'm sorry, this calculator can not compute imaginary solutions."; } } But I want to insert the "else if" statement, which I seem to be doing wrong.Anyone know the (probably embarassingly obvious) solution? If so, can you please show me what to do?Thanks!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now