Skip to content

Instantly share code, notes, and snippets.

@moitorrijos
Created February 18, 2013 20:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moitorrijos/4980258 to your computer and use it in GitHub Desktop.
Save moitorrijos/4980258 to your computer and use it in GitHub Desktop.
A quadratic equation solver in JS
var quadEquationSolver = function (a, b, c) {
var rootPart = Math.sqrt( (b * b) - (4 * a * c) );
var denom = 2 * a;
var firstRoot = (-b + rootPart)/denom;
var secondRoot = (-b - rootPart)/denom;
console.log("The first root is " + firstRoot);
console.log("The second root is " + secondRoot);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment