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

Agnes Caringal
Agnes Caringal
6,239 Points

Alert Function!...How can I make. Anyone can help me to solve this

regarding alert() method

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

alert(max(num1, num2);

3 Answers

You're close! In your alert, pass in some real numbers to make the function work.

function max (num1, num2) {
  if (num1 > num2) {
    return num1;
  }
  return num2
};

alert (max(2,3));
Agnes Caringal
Agnes Caringal
6,239 Points

Thank you so much Sir Ion Jones. How about this?

Given this function, write the code to call it: function warning() { alert('Warning, warning, warning!'); } ;

To call that function:

warning();

That's it.

Agnes Caringal
Agnes Caringal
6,239 Points

Thank you sir Ion Jones :)

---function returns the message variable: ---

function greeting( name ) { var message = "Hello " + name; }

Agnes Caringal
Agnes Caringal
6,239 Points

return greeting()

what's the problem with my code? thanks

Hi Agnes! You need to pass a name into your greeting function.

Like so:

function greeting(name) {
    var message = "Hello " + name;
};

greeting("Agnes");

Also, don't forget the semi-colon at the end of your function call.