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

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Not sure why I got the correct answer.

I was trying to figure an easy way to do this challenge, so I just wrote this:

function max (smaller, larger) {
    return number = larger;
}
alert(max(2, 4));

To my surprise, I got it right. Whether I write it as (2, 4) or (4, 2) when I call the max function, it still shows as correct. Can someone please explain this?

1 Answer

Ioannis Leontiadis
Ioannis Leontiadis
9,828 Points

Hello Christopher,

this function always returns the value of the parameter larger as it assigns it to number and then returns the variable number. The reason you got this right has probably to do with the test cases.

Note: You can try this locally to see that it is failing!