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 trialCasey Rochester
3,626 PointsI want to check which of the two numbers is larger, then return it. How do I do that?
I'm trying to create a function that checks which of two arguments is larger, then returns it. I'm not sure how to proceed.
function max(a+b) {
if(a<b) {
return(5);
} else(b>a) {
return(4);
}
}
1 Answer
Casey Rochester
3,626 PointsThank you so much, Eric! I figured it was something silly that I'd messed up on.
Eric Eisberg
15,999 PointsEric Eisberg
15,999 PointsYou seem to have the general idea, but your syntax could use some work. When setting parameters, you want to separate them by a comma. Also, in this case, you don't ever define your arguments, so I have no idea why you want to return the integer five or four in either case. And finally, the else statement is for all other cases than (a < b), so further elaboration is unnecessary.
I would structure it this way:
You could also set your arguments inside your function, but you would need to set values to a and b or you would be comparing two undefined variables.