0
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?

2
  • theres a semicolon missing after the console.log(...) Commented Jul 1, 2015 at 20:41
  • 3
    @Paul: that doesn't matter in JS. @Tae Rugh: 2a isn't a valid token. (I assume you have a sqrt function somewhere.) Commented Jul 1, 2015 at 20:44

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

They probably intend (2 * a) if that's what they were trying to do with 2a but +1.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.