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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Maurice Hobbs Jr](https://secure.gravatar.com/avatar/e4d5db2b81d21088bc9645a5d2ca8f90?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Maurice Hobbs Jr
5,278 PointsIm stuck on naming the function max
I am getting an error code
function max(length, width ){
if (either(length > width ) || (width < length )){
var answer = either
}
return anwer;
}
![Maurice Hobbs Jr](https://secure.gravatar.com/avatar/e4d5db2b81d21088bc9645a5d2ca8f90?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Maurice Hobbs Jr
5,278 Pointsthank you I changed but I'm still getting the same error
5 Answers
![Amber Stevens](https://uploads.teamtreehouse.com/production/profile-photos/10253582/micro_Me-Pic.jpg)
Amber Stevens
Treehouse Project Reviewerthis is what worked for me:
function max(length, width ){
if (length > width ) {
return length;
}
else if (width > length) {
return width;
}
}
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThis would come close, but the "else if" isn't needed. Plus, if the two values are ever the same this code won't return anything. Having the second "return" stand alone will guarantee a correct return in every case.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsMaurice Hobbs Jr — please don't mark this as "best answer" .. it is not a correct solution even if it passes the challenge. But Amber has left another answer with a correct solution.
![Amber Stevens](https://uploads.teamtreehouse.com/production/profile-photos/10253582/micro_Me-Pic.jpg)
Amber Stevens
Treehouse Project ReviewerBut yes, based on what you said, Steven Parker I found this also worked and is probably more what the challenge was looking for:
function max(length, width ){
if (length > width ) {
return length;
}
return width;
}
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsYes, I'd agree that is a correct solution. Good job!
![Amber Stevens](https://uploads.teamtreehouse.com/production/profile-photos/10253582/micro_Me-Pic.jpg)
Amber Stevens
Treehouse Project ReviewerSo the problem seems to be that you're testing them both in the same statement rather than testing them separately. The variable "answer" as you have it now is basically returning a boolean value of true rather than a number which is what the challenge is looking for. The way that I did this was I tried checking if length is greater than width then return length. else if width is greater than length, then return width
![Maurice Hobbs Jr](https://secure.gravatar.com/avatar/e4d5db2b81d21088bc9645a5d2ca8f90?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Maurice Hobbs Jr
5,278 Pointsit still didn't work but thank you I know I am now on the right track.
![Amber Stevens](https://uploads.teamtreehouse.com/production/profile-photos/10253582/micro_Me-Pic.jpg)
Amber Stevens
Treehouse Project ReviewerHmm.. I might have gone about it a different way I guess, but what I have there DID in fact pass the code challenge :)
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI believe it, some challenges test more thoroughly than others. But you can see that it's important to always return one value or the other. If this were a complied language, you'd most likely get a compiler error "not all code paths return a value".
![Maurice Hobbs Jr](https://secure.gravatar.com/avatar/e4d5db2b81d21088bc9645a5d2ca8f90?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Maurice Hobbs Jr
5,278 PointsI had a couple words backwards and needed to delete a couple things so thank you.
Clark Reilly
6,204 PointsClark Reilly
6,204 Pointsto start, you need to return anSwer, not anwer. But after fixing that, your code still doesn't work and I don't know jack about javascripts syntax, which is why this is a comment and not an answer. According to the compiler, you didn't declare a function named "max()" Mabye you messed up on something there.