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 Functions Pass Information Into Functions Create a max() Function

stumped, idk where to go from here???

script.js
function max (upper, hours) {
return upper + hours;

}

max (10, 3)

1 Answer

Hi Ulyssa, You'll need to use a conditional statement to test which of the two parameters is the largest.

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

You can add additional else statement to check if they are equal:

function max ( a, b) {
  if ( a > b ) {
    return a;
  } else if ( b > a) {
    return b;
  } else {
    return `They are equal`;
  }
}