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

Create a new function which accepts two numbers as arguments, use conditions to test to see which number is larger

Hi All,

I am having problems with this question. I have tested with my own code in the console and with an alert box and it does return the higher value, however it keeps saying I'm incorrect:

  • "Bummer! The max() function doesn't seem to work. It should return the larger of the two numbers." *

Please take a look at my code below, not the prettiest but does return my higher value of 10.

function max(low, high) {
  var low = 1;
  var high = 10;
    if (low < high) {
      return high;
    } else {
      return low;
    }
}

console.log(max());
alert(max());

All help appreciated, Thanks!

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Darren;

Pull your variable declarations out of your function, and when you call the function add them as arguments and it will work just fine.

Ken

Thanks Ken, works great now - I knew it was something very simple.