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

Can't figure out how to pass the second step

Not sure what to do here... Wrote the function out like this and it says syntax error line 1 unexpected number. Wasn't sure what I was doing wrong and played with the code a bit. I passed the first step by replacing the 5 and 10 in the code with mny and str and testing this condition. I would like to know why I am getting a syntax error and how to add numbers to what I think is the parameters of my function inside the first pair of parenthesis. Thank you in advance, appreciate the help.

script.js
function max  (5,10)   {
 if (5<10) {
   return 10
 }
}

2 Answers

Hi Peckeday

Yes the code I gave you earlier was for Task 1. For task 2, you call the max function and place your numbers:

function max(x, y) {
  if(x>y) {
   return x; 
  } else {
    return y; 
  }
}
alert (max(10, 5));

Hi Peckeday

You don't put numbers as the arguments, you give them a name.

function max(x, y) {
  if(x>y) {
   return x; 
  } else {
    return y; 
  }
}

Already did that, wont pass 2nd step. I replaced the mny and str parts of my code with x and y and wrote the code like you did. Than I added alert(max(x,y) ); like the 2nd step asks for and your code doesn't pass either, says Task 1 is no longer passing.