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

Need help with the syntax of this quiz

I keep receiving a syntax error on the following code: function max(n1,n2){ if (n1>n2){ return true}; else { return false}; }

max(1,2);

script.js
function max(n1,n2){
  if (n1>n2){
    return true};
  else {
    return false};
}

max(1,2);

3 Answers

What number should the max function should return?

A function can return a value by using the return keyword. So, you have one of those scenarios:

function max(n1,n2){ if (n1>n2){ return n1} else { return n2} }

OR

function max(n1,n2){ if (n1>n2){ return n2} else { return n1} }

Thanks, that resolved it for me.

Hello there,

You need to remove the semicolons Your code must like this.

function max(n1,n2){ if (n1>n2){ return true } else { return false } }

And it will work

Thanks - the semicolon clean-up resolved my syntax error but I can't get the max to return a value. This is my error now: "The max function isn't returning a number."

I am not sure why it isn't fetching the number from calling my max function below the code.