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 function max task 2 of 2

Keep getting this error and not sure what to do to fix it "Did you pass 2 numbers to the max() function."

script.js
function max (firstNumber, secondNumber){ 
  if (firstNumber > secondNumber) {
    return; firstNumber 
  } else { 
    return secondNumber; } 
}

max(10,9);
alert(max(10,9));

3 Answers

Heidi Puk Hermann
Heidi Puk Hermann
33,366 Points

If you look in line 3 in your code, you have put the semicolon after return, but before the variable you want to return. if you move the semicolon to the end of the line your code should work perfectly.

...
return firstNumber;
...
Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points
function max (firstNumber, secondNumber){ 
  if (firstNumber > secondNumber) {
    return; firstNumber  // ; is mis-placed here
  } else { 
    return secondNumber; } 
}

Oh dang idk how that happened lol thanks guys!