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

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));