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

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

script.js
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);