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

help

function max(one, two){ if(one > two) { return one; } else if (one < two) { return "sorry, better luck next time"; } }

max(20, 15);

? it's running in my js console..?

script.js
function max(one, two){
    if(one > two) {
      return one;
    }
  else if (one < two) {
      return "sorry, better luck next time";
    }
}

max(20, 15);

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Challenges are very specific and have rules that you must follow to the letter for it to pass. It wants you to pass back whichever number is bigger. But in one instance you pass back a string instead of the larger value. Also, it wants you print out the max value in an alert. So while your code is functional, it doesn't meet the criteria for the challenge. I've altered your code so you can see what they're looking for:

function max(one, two){
    if(one > two) {
      return one;
    }
  else if (one < two) {
      return two;
    }
}

alert(max(20, 15));