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

Mathew Yangang
Mathew Yangang
Python Web Development Techdegree Student 2,169 Points

just curious, what's wrong with this code?

Got a couple of errors, not sure what i'm doing wrong

script.js
a = 1;
b = 2;
function max(1,2){
if (b>a)
  return (2);
}

2 Answers

Jon Tang
Jon Tang
5,829 Points

Your functions have to have parameters. Like a and b instead of 1 and 2.

function max (a , b) {
 }

then you state what that function does.

function max (a , b) {
  //Your code here
};

which is...

function max (a , b) {
  if (b > a ) {
    return(2);
  };
};

then use console.log to return your results

function max (a , b) {
  if (b > a ) {
    return(2);
  };
};
console.log(max(1, 2));

this should return 2 in the web console