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 trialBrian Patterson
19,588 PointsNot sure what is wrong?
Not sure what is wrong with this code?
function max(width, length) {
if (width < lenght)
return width;
}
1 Answer
Steven Parker
231,269 PointsWell, you're part way there. You want to return the LARGER of the two, so you need to reverse your test. Then, you need to return the OTHER value if the test fails (using else):
function max(width, length) {
if (width > length) // if width is LARGER
return width; // ...then return width
else
return length; // otherwise return length
}
You can actually omit the else if you want, since the function would have already returned in the other case.
Jacob Cordeiro
2,796 PointsJacob Cordeiro
2,796 Pointshave you assigned the perimeters?