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

I'm not sure what is wrong with my code, I am sure it has to do with my syntax. I had to take a break from the track.

Because it's a challenge I can't see any example of the code to compare to my own. I've completed all the other challenges and lessons in this track but I need this one for completion credit. Thanks.

script.js
function max( upper, lower ) {
return upper if {
  upper > lower
} else if {
  return lower if upper < lower } 
  }
max(12, 15);

1 Answer

There are some syntax errors. I hope this makes sence :-)

function max(lower, upper) {
  if (upper > lower) { // condition first
    return upper; // then return
  } else { // an else is enough since this function only returns lower or upper
    return lower;
  }
}
max(12, 15);

Thank you so much! Your notation makes sense. I appreciate the response.