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

brayant benitez
brayant benitez
7,885 Points

error on this lesson

I keep getting an error but i cant seem to figure out where i am going wrong.

function max(1, 2) { if(1 > 2) { return 1; } else { return 2; } }

alert(max(1, 2));

script.js
function max(1, 2) {
  if(1 > 2) {
  return 1;
  } else {
    return 2;
  }
}

alert(max(1, 2));

1 Answer

Parameter names can't start with a number and also can't be a number itself.

Try changing the parameter names to a different one like "a" and "b".

function max(a, b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

alert(max(1, 2));

Good luck! ~alex

brayant benitez
brayant benitez
7,885 Points

wow thank you so much this works, now i understand this a little more

I'm happy to help :)