JavaScript JavaScript Basics Creating Reusable Code with Functions Create a max() Function

Gareth Partridge
Gareth Partridge
9,690 Points

Create a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would l

I am getting syntax errors, does anyone perhaps see something I dont?

script.js
function max(12, 3)        
    if(12 > 3) {  
    return 12; 
  } else {
    return 3;
  }
}

3 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 52,029 Points

Despite the instructions you can't name the arguments/parameters whatever you like. Follow the naming conventions for variables and you should be good. See JavaScript Identifiers here

You are also creating a function whose purpose would be to handle any input. Not just 12 and 3.

Mirko Aus
Mirko Aus
1,687 Points

That's how I solved it. I wasn't quite understanding the wording of the problem so it took slightly longer than usual to solve it. As Kris mentioned, you can't define parameters as some exact numbers and words.

function max (value, value) { if (arguments[0] > arguments[1]) { return arguments[0]; } else { return arguments[1]; } }

max(1, 2); // arguments[1] or number 2 is returned because arguments[0] value is smaller than arguments[1]

chuck kotulka
chuck kotulka
3,528 Points

Create a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would like). The function should return the larger of the two numbers.

I am stuck! Any Help?