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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.