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 trialantonio morales
912 Pointsi am stuck
i am not sure what i am doing wrong here
function max (bad,good) {
if(bad > good) {
return bad;
}
return good;
}
max(bad,good);
if ( bad <good) {
}
alert( ("bad < good") );
3 Answers
Steven Parker
231,236 PointsYou need to move the call to the "max" function to inside the argument area (parentheses) of the "alert" call. And where you call the function, give it a couple of numbers for arguments instead of the parameter names.
And you won't need an "if" outside of the function.
furkan
11,733 PointsAnswer to first part:
function max(a,b) {
if (a > b ) {
return a;
} else {
return b;
}
}
Answer to second part:
function max(a,b) {
if (a > b ) {
return a;
} else {
return b;
}
}
alert( max(2,3) ) ;
Where you made the mistake:
1) you have not used the else keyword for the second condition
2) you need to remove the secobd if statement and instead replace with an else statement like in my example.
I hope that helped. All the best ?
Steven Parker
231,236 PointsThe function is correct as-is, no "else" is needed. That's because when the condition is true, the function exits — so effectively the entire remaining code in the function is only done "else".
furkan
11,733 PointsSo just having the first if statement would do?
Steven Parker
231,236 PointsYes, you only need the "if" and no "else". You never need an "else" when the "if" contains a return.
furkan
11,733 PointsThanks for the clarification ?
antonio morales
912 Pointsantonio morales
912 Pointsthank you
Steven Parker i always miss these things