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 trialThaddeus Lorenz
3,434 PointsCan someone help me find the problem?
For some reason, my first task doesn't work after trying to complete the second task. Can someone please help me figure out what I'm doing wrong?
function max( a, b) {
return (a,b);
if (a > b) {
return max(a);
} else {
return max(b);
}
}
3 Answers
cortneyltaylor
9,561 PointsThe return in Javascript ends the function, so anything after your first return statement doesn't run. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Sean T. Unwin
28,690 PointsWithin function max
:
// pseudocode
// Conditional: Is a greater then b
// yes: return a
// no: return b
cortneyltaylor
9,561 PointsJust remove your return statement on line 2 and it should work.
function max(a, b) {
if (a > b) {
return max(a);
} else {
return max(b);
}
}
Thaddeus Lorenz
3,434 PointsThank you for responding but it's saying that I don't have a function named 'max()' anymore.
Thaddeus Lorenz
3,434 PointsThaddeus Lorenz
3,434 PointsHow am I supposed to have both returns at the end of the entire function with an "else" separating the function?