Read stories by different users


quad equation solver
Franklol

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript" src="quadEquation.js"></script> <title>Javascript based graphing calculator</title> </head> <body> <div style="text-align: center;"> <h1>Quadratic Equation Solver 2K15<br> </h1> </div> <div align="center"> <form name="form"> <input name="x2Coef" size="2" value="1" type="text"><b> X<sup>2</sup> </b> <select name="firstSign"> <option value="+">+</option> <option value="-">-</option> </select> <input typle="text" name="xCoef" size="2" value="1"><b> X</b> <select name="secondSign"> <option value="+">+</option> <option value="-">-</option> </select> <input name="endValue" size="2" type="text"><br> Round to the nearest thousandths?<input name="round" type="checkbox">Yes<br> <br> <input value="Solve!" onclick="SolveEq()" type="button"></form> <p id="testing" style="border: 2px groove orange; width: 400px; height: 100px; font-size: 16px; color: blue;">The Solution Will Appear Here!</p> </div> </body> </html> now for the quadEquation.js var a,b,c,x1,x2; function getValues() { signB = (document.form.firstSign.value == "+") ? 1 : -1; signC = (document.form.secondSign.value == "+") ? 1 : -1; a = document.form.x2Coef.value; b = document.form.xCoef.value * signB; c = document.form.endValue.value * signC; } function solveForX() { x1 = ((-1*b) + Math.sqrt((b*b) - 4*a*c))/ (2*a); x2 = ((-1*b) - Math.sqrt((b*b) - 4*a*c))/ (2*a); if(document.form.round.checked){ x1 = Math.round(x1*1000)/1000; x2 = Math.round(x2*1000)/1000; } } function factorEq() { if( (Boolean(x1) != false) && (Boolean(x2) != false)) { x1Print = ((x1 * -1) > 0) ? "+" + (x1*-1) : x1 * -1; x2Print = ((x2 * -1) > 0) ? "+" + (x2*-1) : x2 * -1; aPrint = (a > 1 || a < 0) ? a : ""; document.getElementById('testing').innerHTML = "<font color=\"red\">The Solutions Are:</font><br>x1 = " + x1 + "; x2 = " + x2 + "<br><font color=\"red\"> The Equation Is:</font><br> " + aPrint + "(x " + x1Print + ") (x " + x2Print + ")"; } else { document.getElementById('testing').innerHTML = "<font color=\"red\"><b>YOUR INPUT PRODUCED AN ERROR:</b></font><br> You have entered a non-integer into one of the fields above, or the solution(s) for your equation is(are) an imaginary(s) number!"; } } function SolveEq() { getValues(); solveForX(); factorEq(); }


Please Login to post a comment

Andrew

1+1=2

Liang

This is a sexy calculator Good job frank