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

Need assistance getting this code started

not accepting numbers in max function

script.js
function max (4, 20) {

}

3 Answers

To get some clarification, are you trying to use Math.max(a,b) or a function named "max" that's trying to pass two numbers into the function?

If you are trying to use Math.max(4,20) then you have to use Math.max(4,20) to get it to return 20.

Sorry, I didn't relize that this was part of a Code Challenge. Given the code challenge you are looking at developing a function named max that accepts two arguments; here's what I did:

function max( x, y ) {
 if ( x > y ) {
   return x;
 } else {
   return y;
 }
}

max(4,20);

When you call max(4, 20); then it will retrun 20 (which would go in as y)

Thanks Jeffery, I am trying to use function max keep getting error message

I followed it up with my code snippet above, did you get a chance to review that?