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

Robert Rydlewski
Robert Rydlewski
3,045 Points

What'sc wrong with this code ??? I created the function, I made the argument of (4,9) inside the function and made ..

and made the conditional statement. What I missing ??? Please help

script.js
function max(x,y) {
 return max(4,9)
  if (x < y ) {
    document.write("x is bigger then y");
  }
  else {
    document.write("x is smaller then y");
}
Martin Lewis
Martin Lewis
10,103 Points

Hi Robert there a couple of issues with the code that has been written. Where you have called the function, this will not work, the function needs to be called outside of the function. Also try calling it without the return as well.

function max(x,y) {
  if (x < y ) {
    document.write("x is bigger then y");
  } else {
    document.write("x is smaller then y");
  }
}

max(4,9)

Hope this helped.

2 Answers

Robert Rydlewski
Robert Rydlewski
3,045 Points

Thanks, guys :) I appreciate your help