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

What is the purpose of including unnecessary(?) arguments in this function?

Create a function that takes 3 arguments - a, b, and c. If a is an even number have the function return the string "even." Otherwise have the function return the string "odd."

I wrote a function that works without arguments b and c, so I am not seeing the value of including them.

Tl;dr What is the purpose of including arguments b and c in this function?

var extraCredit = function (a, b, c) { if (a % 2 === 0) { return 'even'; } else { return 'odd'; } }

You're right. Based on what you're telling us, there doesn't seem to be any reason to have 3 arguments in there.

Maybe the question wanted an answer like this?

// allows you to pass in a custom return value for true/false cases
function isEven(a, b, c) {
    if (a % 2 === 0) {
        return b;
    }
    else {
        return c;
    }
}

var extraCredit = isEven(5, "even", "odd");

I can't imagine why anyone would want to go to that degree of effort for something so simple though.

Maybe there's something else going on in the context of the question that we're missing. I don't know what question you're referring to though so it's hard for me to say...

I wonder this extra credit problem comes from which Treehouse course.

Thanks, Jessica. I guess there really is no right answer. I remember the person who suggested Treehouse to me basically saying there are no right answers, just more efficient ways of doing things. This is that, I think. Glad I asked. Your answer got me thinking outside of the box.

William: I should have included that. Thanks. http://teamtreehouse.com/library/introduction-to-programming

Treasure Porth
Treasure Porth
Treehouse Teacher

People have apparently been wondering about this for a long time: https://teamtreehouse.com/forum/extra-credit-for-functions-badge

Someone people theorize that you're supposed to check if the sum of a, b and c is even or odd. I'm so curious now, I hope someone answers.

3 Answers

Hi, Ryan, I just took a look at that extra credit problem

Create a function that takes 3 arguments, a, b, and c. If a is an even number have the function return the string "even". Otherwise have the function return the string "odd"

And I agree with you, there's no need for b, c arguments for this function, and your implementation of the function is perfect. I'd suggest staffs at Treehouse (Dave McFarland maybe?) to change the description of this problem, it's giving instruction for student to write code in bad style, because you never pass in unnecessary argument to function that it's not gonna be used in the function body.

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Ryan Dailey

I agree that that description doesn't make much sense. I've changed it so that it only asks for a single argument: http://teamtreehouse.com/library/introduction-to-programming

Also, Introduction to Programming and JavaScript Foundations will be retired sometime in the near future. They are being replaced with JavaScript Basics and JavaScript Loops, Arrays and Objects.

Thanks for tagging me William Li

Dave, today I read a thing that says modesty doesn't work in the coding world. How about this then? "If this bug hasn’t been reported before, we’ll award you with a special Exterminator badge as a thank you!"

Dave McFarland
Dave McFarland
Treehouse Teacher

Alright Ryan Dailey you've got your exterminator badge!

Thanks for bringing this bug to my attention.

But I do believe that modesty is a good virtue -- there are a few programmers I've worked with in the past who could use a little of it ;)

:o ... you actually gave out an exterminator badge. That's awesome lol.

So uh... remember that trailer NaN bug? *wink wink*

Hahaaaa... that's awesome. You rock Dave.

Cheers!

Thanks for the recommendation, William. I absolutely will do that. I am curious whether or not I caught a bug.