Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

challenge # 1

syntax error

function max(20, 15){

  if (20 > 15) {
      return 20;
      return 15;

1 Answer

18,780 Points

You've got the general structure, but it's a little bit more tricky than that. They don't want you to hard code the numbers in there, since that isn't very useful. Instead, you want to write a function that will return the larger of any two integers you pass.

function max(num1, num2) { // This is the same function you have, but with variables instead of hard coded numbers.
  if (num1 > num2) { // You've got the right idea, but use the variable names instead.
    return num1;
  } else {
    return num2;
max(13, 7); // Here's where you call your new function with any two numbers you like.

It's worth noting that you don't have to include an edge case for if the two numbers are the same. Let me know if you have any more questions. Happy coding!