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

Curtis Simonson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Curtis Simonson
UX Design Techdegree Graduate 13,791 Points

Create a Max() Function

Here is my new code

script.js
function max ( ){
    if max (big, little){
     return big;
  } else max (big, little){
    return little;
 }

}

  max(2, 1);

1 Answer

John O.
John O.
4,680 Points

You've got a couple issues here:

Your function should accept 2 arguments

function max(a, b)

Within your function definition you need to make a comparison to see which one of your arguments (a or b in my case) is greater. So your function should look something like this:

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

Since we're only dealing with 2 values you only need to make one conditional check.

You don't need to call your max function from within your max function declaration. You are missing the conditional check.