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

Hui Zheng
PRO
Hui Zheng
Pro Student 1,380 Points

function max(big, small){ if(big < small){ return big; }else{ return small; } alert(max(12, 10));

I followed the instructions to write out this code but I kept getting the syntax error message. I have no idea of what I

script.js
function max(big, small){
  if(big < small){
    return big;
    }else{
      return small;
}
alert(max(12, 10));

3 Answers

rydavim
MOD
rydavim
Treehouse Moderator 16,911 Points

The parse error is due to missing a closing curly-brace at the end of your max function. Adding that in should get you to a more helpful hint about your solution on the challenge page.

function max(big, small){
  if(big < small){
    return big;
    }else{
      return small;
} // closes the else
} // one more here to close the function
alert(max(12, 10));

If you run into trouble though, let me know and we can walk through a solution. Happy coding!

Hui Zheng
Hui Zheng
Pro Student 1,380 Points

function max(big, small){ if(big > small){ return big; } else { return small; } } alert(max(12, 10)); I revised the code to this, but afterwards I still received the syntax error.

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 49,951 Points

Two things:

1) You are missing a closing bracket for your else statement

2) The function should return the larger of the two numbers.

Hui Zheng
Hui Zheng
Pro Student 1,380 Points

Can't believe I had overlooked it. Besides the closing bracket everything else on the code was good right?

Thank you Maim

Hui Zheng
PRO
Hui Zheng
Pro Student 1,380 Points

It works now. Thanks so much for the help everyone