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 trialRUPESH BASUDE
2,932 Pointslarger of 2 numbers
create a new function named max() which accepts two numbers as arguments.The function should return the larger of the two numbers. use the conditional statement to test the 2 numbers which one is large? can anyone please tell me how to do this?
function max(1,2){
if(1<2){
return 1;
}
else{
return 2;
}
}
1 Answer
Troy Riggs
13,859 PointsYou've got the right idea. You just need to swap out the numbers for variables. That way, it's a function that can tell you the max of any two numbers.
function max( a, b ) {
if ( a > b ) {
return a;
}
return b;
}
RUPESH BASUDE
2,932 PointsRUPESH BASUDE
2,932 PointsThank you very much for your answer.