Reputation: 1
var quadraticFormula = function(a, b, c) {
console.log((-b + sqrt( (b*b) - 4 * a * c)) / 2a) };
quadraticFormula(2,2,2)
I am a beginner trying to make a simple quadratic equation calculator on javascript. I keep on getting a syntax error message saying "missing ) after argument list". What is wrong with my code?
Upvotes: 0
Views: 324
Reputation: 2178
Try adding a *
sign in 2a
:
var quadraticFormula = function(a, b, c) {
console.log((-b + Math.sqrt( (b*b) - 4 * a * c)) / (2*a));
};
Also sqrt
is part of Math
so invoke it with Math.sqrt
. Notice that quadraticFormula(2,2,2)
will print NaN as it will try to do the square root of a negative number: (2*2) - 4 * 2 * 2.
Edit:
I wrapped 2*a inside ()
to correct the quadratic formula.
Upvotes: 4