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

Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the

dont know whats wrong

script.js
function max(10, 12) {

    if(10 > 12) {
      return 10;
    } else if (12 > 10) {
      return 12; 
    }
}
    alert(max(10, 12));

2 Answers

Your parameter names should follow naming rules. From MDN

A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).

Em Har
Em Har
9,775 Points

Youre basically almost there, so good job on that. Keep in mind parameters are there to call in different numbers. If you put 12,10 for them, then this function will always have those numbers in them. Thats why we put names for it so when we do CALL the function, we ADD the parameters afterward because sometimes you want different numbers inside. Check below to see an example:

function max(smaller, larger){ if (smaller < larger){ return larger; } };

alert(max(1,2));

This way we can call the function and put any number in it.