Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Hui Zheng
PLUS
Hui Zheng
Courses Plus 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
rydavim
18,814 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
Courses Plus 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.

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
Courses Plus 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
PLUS
Hui Zheng
Courses Plus Student 1,380 Points

It works now. Thanks so much for the help everyone