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 keep getting this error "The `max` function isn't returning a number." I ran this code in the console and it runs fine

Please take a look at my code and let me know if you can help.

script.js
function max(numberOne, numberTwo) {
    var maxNumber = numberOne;
    if (parseInt(maxNumber) > parseInt(numberTwo)) {
      return (parseInt(numberOne)) + " " + 'number one is larger';
    } else {
        return (parseInt(numberTwo)) + " " + 'number two is larger';
  }
}
max(59, 99);

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

This is because you are just supposed to return the larger of the two numbers, you are returning a string containing the number and extra words. You just need the return the number, so this is a case of not returning the proper output.

Thank you quick response and I cut the code down and it worked fine. Bob