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 Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Rense Zwarteveen
Rense Zwarteveen
4,925 Points

Stuck at max functions

i have to make a alert dialog to few the result. but i don't know how. Can anyone help me. beneath my written code:

function max(ten, five) { if (ten > five) { return ten; } return five; } alert(math.random(10, 5);

script.js
function max(ten, five) {
  if (ten > five) {
    return ten;
  } return five;
}
alert(math.random(10, 5);

3 Answers

jason chan
jason chan
31,008 Points
function max (argument1, argument2) {
     if (argument1 > argument2) { return argument1;} 
       return argument2;
}

max(10, 5); //Here I'm changing the value of the arguments and it will return 10
Rense Zwarteveen
Rense Zwarteveen
4,925 Points

Thanks for the quick answer. But i have to make the next challenge.

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

For example, to display the results of the Math.random() method in an alert dialog you could type this:

Do you know, how to do this? i realy don't know.