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

Varun Khanna
Varun Khanna
1,831 Points

doesnt seem to work.

please check

script.js
function max (){
  var y = prompt ("Number1");
  var z = prompt ("Numnber2");
  var x = Math.max (y,z);
  return x;
}

2 Answers

Jack Gordon
Jack Gordon
9,232 Points

Within your function of max you need to pass 2 parameters which we can name anything like so:

function max(number1, number2) {
      return Math.max(number1, number2);
}

max(200, 201);

then you simply need to return the Math.max instead of creating the variables individually (I know what you tried to do though!)

The best bit about the parameters is that we can make them whatever numbers we like when we call the function so where max(number1, number2), I have instead put max(200, 201) as arguments to test.

I hope that makes some sense, please comment if you would like me to clear anything up better!

Taylor Boudreau
Taylor Boudreau
7,285 Points

Hi there Varun,

It looks like this challenge is asking for the two numbers being compared to be passed in as arguments rather than as user input. Kind of like so:

function max(x, y) {
}

I hope that helps!

Taylor