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

Syntax Error: Parse Error? What?

The task is asking me to create a function that has two numbers as parameters, and returns the larger number. However, when I put in two numbers, it says Syntax error: Parse Error. In addition, they want me to use a conditional statement to test which number is larger. Where do I add the conditional statement, and where is the syntax error they speak of?

Here's the challenge I'm on:

https://teamtreehouse.com/library/javascript-basics/creating-reusable-code-with-functions/create-a-max-function

script.js
function max(2, 5) {

}

1 Answer

Nick Yoho
Nick Yoho
6,957 Points

Try using variables instead of numbers within your function and you won't get a parse error, for example.

function max(num1, num2) {
}

You're conditional statement will be within the function, so whenever the function runs, it will check to see which variable has the greater value. With out giving it away here is a basic structure of how it should look

function max(num1, num2) {
  if (){
      return 
  } else {
      return 
  }
}

It worked: Thank you so much!