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 Functions Pass Information Into Functions Create a max() Function

Jordan Branch
Jordan Branch
2,762 Points

SyntaxError: script.js: 'return' outside of function `r` (6:4)

I think I'm inputting something wrong or i got my parameters wrong?

function max(highNumber, lowNumber) {
  return highNumber;

if(highNumber >= lowNumber) {
    return true;
} else {
    return false;

1 Answer

That's a syntax error, the function is supposed to wrap the rest of codes in.

However, there's a few problems here. Your function is returning the first parameter and the rest of the codes are returning boolean when it's supposed to return integer. I would also consider renaming the parameters because we don't know which one is greater than the other:

function max(x, y) {
    if (x > y)  {
        return x;
    } else if (y > x) {
        return y;
    } else {
        // executes only when both numbers are equal
        return x; // or return y;

You can name the parameters num1, num2 that's totally up to you, but highNumber, lowNumber would indicate that the first parameter should be greater and the second parameter should be less.

Jordan Branch
Jordan Branch
2,762 Points

So instead of highnumber, lownumber i should make it something neutral?

Yeah, something more general, because lowNumber > highNumber logically doesn't make sense.

x and y, alpha and bravo, num1 and num2, names that are very general or uncertain. In this case I'd choose either num1 and num2 or number1 and number2.

Enlighten me if you come up with better names! Hope this helps!

there is no need of else after a return though.

You're right, very ignorant of me not to know the existence of >=.