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 trialDerek Kauble
2,855 PointsWhy the parse error?
I'm not sure why I'm getting an error trying to return the larger of the two variables.
function max(x, y) {
if (x > y ) {
return x;
}
else {
return y;
}
2 Answers
Mark Ihrig
19,966 PointsThere is a space before your y on the first line, and a space after your y on the second line. I think that might need to be tightened up. There also appears to be a curly bracket missing at the bottom of your code to close it out properly. The following is the correct code:
function max(x,y) {
if (x > y) {
return x;
} else {
return y;
}
}
Rich Donnellan
Treehouse Moderator 27,696 PointsAs Mark Ihrig states, you were missing the function's closing curly brace; white space didn't matter here.