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

Alex Antoniu
Alex Antoniu
4,557 Points

i got this error always Oops! It looks like Task 1 is no longer passing.

i cant complete this task

script.js
function max(a, b) { if (a > b) { return bigNumber = a; } else { return bigNumber = b; } } alert(max(a, b));

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Alex,

If you are getting that error, I'm assuming it is Task 2 you are struck on. I think you may have over-thought what is being asked for Task 2.

Just to make sure, this is the working code for Task 1, where you create the function max that takes two arguments and returns the larger of the two.

var max = function(a, b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

For Task 2, all you have to do is call the function in an Alert box, and pass in your own parameters. So just add the function call below the complete code from Task 1.

alert (max (5, 9));       //you can use whichever numbers you like

Hope that helps. Keep Coding! :)

A couple things wrong with your code. When returning a variable you can simply return the variable itself. Also your alert should pass numbers rather than the parameters of the function. view below

function max(a, b) { 
    if (a > b) { 
        return a; 
    } else { 
        return b; 
    } 
} 
alert(max(100, 99));

I hope this helps.