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

Nicholas Chetto
Nicholas Chetto
4,221 Points

basic java script challenge. ive tried multiple way and multiple arguments but still no real answer.

I've tried multiple ways even went back to the videos took notes and changed up arguments but still nothing is working any help would be nice.

script.js
function max(lower, upper){
  if(lower(10) < upper(20)){
    return max = true;
  }else{
    return max = false;
  }
}

2 Answers

Charlie Gallentine
Charlie Gallentine
12,092 Points

When you pass the arguments into the function's body, you do not need to specify values. The arguments are enough in of themselves.

function max(one, two) {
  if (one>two) {
    return one;
  } else {
    return two;
  }
}

Additionally, you do not need to return boolean values. According to the question, you only need to return the value of the function.

For the second part of the challenge, to call the function, you pass the arguments into the parentheses after the function declaration:

// Calls max with values of 10 and 20 in place of 'one' and 'two'
max(10, 20);
Steven Parker
Steven Parker
229,732 Points

You won't want to test fixed values in your function, but instead test the values represented by the arguments (named "upper" and "lower" in this case).

Also, "max" is the name of your function, so you won't want to assign it. You don't need an assignment inside the return statement anyway, just return the value.

Finally, you won't need "true" and "false" in this challenge. In each case you will return one of the arguments that was passed in (the bigger one).

I'll bet you can do it now without an explicit spoiler.