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 trialIsa Abo-Mohana
2,655 Pointswhat I'm doing wrong here?
i should be missing something but i don't know what
function max (long,long1) {
if (long > long1) {
return long;
} else
return long1;
}
}
2 Answers
Steven Parker
231,269 PointsYou're missing a brace ("{
").
The brace that should come right after the "else" to indicate the beginning of the code block is missing.
Another way to do it would be to remove the else and the following close brace, since when the if is true, the function will end (because of the return) before it goes any further.
Ivan Bagaric
Courses Plus Student 12,356 PointsYou can use it on 2 ways
in your case you have too much }
function max(a, b) {
return (a > b) ? a : b;
}
is same as this:
function max(a, b) {
if (a > b) return a;
return b;
}
Steven Parker
231,269 PointsThe ternary operator may not have been introduced in the course yet.
Steven Turner
20,146 PointsSteven Turner
20,146 PointsYou have an extra right bracket. When you are dealing with simple returns like that, it's just easier to drop the else statement as it's a little redundant.