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

can someone please help I don't understand

script.js
function max (3, 6) {
  if (6 > 3) {
    return 6;
  } else {
    return 3;
  }
console.log( addNumbers(3,6) );

2 Answers

Bonus:

I prefer declaring functions like this, however:

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

which can also be shortened to this using ES6 arrow function syntax:

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

More info on ES6: https://codeutopia.net/blog/2015/01/06/es6-what-are-the-benefits-of-the-new-features-in-practice/

thank you that helps alot

The objective is: Create a function named max that accepts two numbers as arguments (name the parameters whatever you would like). The function should return the larger of the two numbers.

(Hint: pass the parameters in the function as variables, as in 'a' & 'b' or 'x' & 'y' or 'param1' & 'param2')

So my solution would be

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

console.log( max(4, 7) );

Will log 7 to the console.

thank you so much