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 trialTshering Tamang
3,492 PointsJavascript Argument
function max (a,b ){ if (a>b){ return a ; }else{ return false; } } max (20, 10);
What is wrong in this code.? Any suggestion It should take two number as argument and return the greater number . Thanks in advance
function max (a,b ){
if (a>b){
return a ;
}else{
return false;
}
}
max (20, 10);
1 Answer
andren
28,558 PointsYour code is quite close, but what happens if you say run your function like this: max(10, 50)
? The function should return the largest number, but it will actually return false
since the first argument is not greater than the second.
In your else
code block you should return the second argument like this:
function max (a,b ){
if (a>b){
return a;
} else{
return b;
}
}
Then your code will pass the first task.
Tshering Tamang
3,492 Pointsappretiate that... moving forward .thanks
Mathew Tran
Courses Plus Student 10,205 PointsMathew Tran
Courses Plus Student 10,205 PointsFor this function, it's probably good to sit down and think why you are having this error.
Q: "What is the max function supposed to do?" A: "It should return the greater number, given number A, and number B"
In layman terms, the max function should do the following:
Given 2 numbers, A and B: If A is bigger than B, return A If B is bigger or equal than A, return B
Your current code logic:
Your "else" statement is the issue :)