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

Colin Stell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Colin Stell
Front End Web Development Techdegree Graduate 25,702 Points

I'm not sure where to go to figure this problem out.

Having trouble figuring this out. I'm got my parameters and what seems to be a conditional statement that should return the correct number. I'm lost. I'm working to return largest sum of whatever is put into the parameters when I call the function.

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

1 Answer

Christian Mangeng
Christian Mangeng
15,970 Points

Hi Colin,

two things here:

1) The else statement does not take any condition because it already covers all of the cases that are not covered by the if statement. So you should remove that condition part. "Else" works in this case because if the numbers are equal, it wouldn't matter which of the two gets returned (num2 is fine)

2) You do not need to call the function at the end

The rest looks fine