Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Brock Alleman
Brock Alleman
2,337 Points

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

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

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);
Brock Alleman
Brock Alleman
2,337 Points

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