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

reate a new function named max which accepts two numbers as arguments

function max(10, 20) { if (10 >20) { return 10; } else { return 20; } }

script.js
function max (10, 20) {
    if (10 > 20) {
        return 10;
    } else {
      return 20;
    }
}

think of arguments, not as literal numbers but variables because you want to be able to reuse the function more than just one time. So, you could recreate the function as: function max (first, second){ if(first > second){ return first; } else { return second; }

1 Answer

functions are the most confusing thing I have done so far with programming but I think I am starting to get it. It will probably make more sense when I use functions for more real work applications rather than just example exercises.

Andrew Aramouni
Andrew Aramouni
2,370 Points

ya Justin I agree. I was completely lost some times studying functions.