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

I need to call a function with two arguments and display it in an alert dialog... Please help!

function max (num 1, num2) { if (num1 > num2) { alert ('True') ; } else { alert ('False') ; } }

script.js
function max (num1, num2) {
  if (num1 > num2) {
    return num1
  } else {
    return num2
  }
}

function max (num1, num2) {
  if (num1 > num2) {
    alert ('True');
  } else {
    alert ('False') ;
  }
}

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Michael.

The first part of the challenge, you have correct with your first function. The second function is not needed in neither the 1st nor the 2nd part so just delete it completely.

The second part of the challenge want you to call the function you created in the 1st part. To call a function, you just type the name and insert the two arguments needed. To make this show in an alert box, simply wrap the function call in the alert method. This would go under the your function from task 1.

alert(max(5, 6));

(or any numbers you wish)

Hope that helps. Keep Coding! :)

You have two different functions with the same name which isn't allowed.

Your first max function definition will return the bigger number.

The second max function definition will alert 'True' if the first parameter is greater than the second and alert 'False' otherwise.

So according to your question "I need to call a function with two arguments and display it in an alert dialog... Please help!" the second max function definition does display an alert box, but only with the value True or False, if you want to alert the two parameters passed into max you could do

alert(num1 + " " + num2);

What would that look like if I typed it in JavaScript?

Thank you Jason! alert (max (5, 6) ) ; worked!