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

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!