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

Jovany Alvarez
Jovany Alvarez
4,462 Points

Finally, call the max function with two number arguments. Display the result of the function in the browser's JavaScript

function max(beaner1, beaner2 ) {
return beaner1, beaner2 ;

2 Answers

To call a function, you type the function's name, then one opening and one closing parenthesis, such as max(). To call a function with one argument, you include the argument between the parentheses, such as max(0). To call a function with multiple arguments, you include comma separated arguments between the parentheses, such as max(0,1,2). The challenge is expecting two number arguments.

To display something in the console, you can use the method console.log(). For example, console.log('a') will log 'a' to the console.

Your max function passes both parts of the challenge without needing to modify it, but it does not determine which number is larger. Instead, it always returns the value of beaner2, which is the second argument passed in. If you pass in the numbers 0 and 1, it returns 1. If you pass in the numbers 1 and 0, it returns 0. The order of the arguments should have no effect on which number is greater than the other.

const par1 = 3; const par2 = 5; function max(par1,par2){ if(par1<par2){ return par2; } } max(par1,par2); console.log(par2);