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

Julien Arseneau
seal-mask
.a{fill-rule:evenodd;}techdegree
Julien Arseneau
Full Stack JavaScript Techdegree Student 5,200 Points

Can someone explain to me how to do this challenge, please?

I do not understand how to return my arguments.

script.js
function max(x, y)
var sink = x * y 
if (x > y) {return x;}
else {return y;}
Brandyn Lordi
Brandyn Lordi
17,778 Points

You also need to wrap your function in curly braces and end each line 2 with a semicolon, then you simply need to call the function and pass through your parameters.

Also, it looks like you are defining var sink = x * y but you aren't doing anything with it.

Your code should look like this:

function max(x, y) {
var sink = x * y ;
if (x > y) {return x;}
else {return y;}
}

// run the function 2 times

max(5,3);
//returns "5"

max(48,49);
//returns "49"

Part 2 of challenge

alert( max(2,5) );

2 Answers

Steven Parker
Steven Parker
231,236 Points

Brandyn's suggestion of enclosing the function body in braces is correct, and should get you past task 1.

But the line creating the variable named "sink" doesn't seem to do anything for the function and while it doesn't prevent passing the challenge it really shouldn't be there.