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 trialCurtis Simonson
UX Design Techdegree Graduate 13,791 PointsCreate a Max() Function
Here is my new code
function max ( ){
if max (big, little){
return big;
} else max (big, little){
return little;
}
}
max(2, 1);
1 Answer
John O.
4,680 PointsYou've got a couple issues here:
Your function should accept 2 arguments
function max(a, b)
Within your function definition you need to make a comparison to see which one of your arguments (a or b in my case) is greater. So your function should look something like this:
function max(a, b) {
if (a > b) {
return a;
} else {
return b;
}
}
Since we're only dealing with 2 values you only need to make one conditional check.
You don't need to call your max function from within your max function declaration. You are missing the conditional check.