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

has anyone got the fix for this; create a function that accepts two numbers, and returns the larger number. see below!!

Create a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would like). The function should return the larger of the two numbers.

HINT: You'll need to use a conditional statement to test the 2 parameters to see which is the larger of the two.

Thanks!!

script.js
function max (num1,num2){

 if (num1)

}

2 Answers

function max(bigger, smaller) {
if ( bigger > smaller ) {
return bigger;
}
else {
return smaller;
}
}

This function tests the parameters that YOU give it. The function means nothing unless you tell it what you want from it. So if you wanted to see if 3 is bigger than 2 then you would simply call the function you just created like so:

max(3,2);

Hope this helps!

you have to create a test that compares the two numbers against each other. For instance, your test would check if one number is larger than the other. Is a larger than b?