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 Giving Information to Functions

Durdona Abdusamikovna
Durdona Abdusamikovna
1,553 Points

my answer for a challenge question gives an error ...

Hello there,

I understood the concept about parameter and argument and trying to solve a problem and came up with an answer below ... In the console answer is right but getting 'event handling error' ... Please give me a clue to find a solution but not the actual answer. I tried different approaches nothing work yet. The task is to create a function with two numbers as argument and compare them to find larger one then return the larger one. I would appreciate any feedback. Thank you beforehand

    function max (large, small){
        if (large > small) {
            return large;
        } 
    }
    console.log(max(90, 11));

1 Answer

Devin Scheu
Devin Scheu
66,191 Points

Your really close! All you has to do is add a else statement and return the other one, i'll try to show you without giving the full answer. Like this:

    function max (large, small){
        if (large > small) {
            return large;
        } else {
         //code here
        }
    }
    console.log(max(90, 11));

If you think my answer was good, feel free to mark it as best answer below, if you need more help in the future from me, you can contact me at devinwscheu@gmail.com.

Durdona Abdusamikovna
Durdona Abdusamikovna
1,553 Points

It is really funny after posting my question I realized that too :) here is my actual answer

    function max (large, small){
        if (large > small) {
            return large;
        } else {
            return small;
        }
    }
    console.log(max(90, 11));

All is ok now :) Thanks for a prompt response