Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Y K
Y K
3,390 Points

Extra Credit for Functions Badge

I'm working on Extra Credit for Functions Badge.

And here is the question. 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"

So far I got following:

var EvenOdd = function (a, b, c){
if(a % 2 == 0){
    console.log("even")
}
else {
    console.log("odd")
}
}
EvenOdd (a == 2)

But no luck…Could anyone give me some more hints?

7 Answers

Y K
Y K
3,390 Points

Thanks J.T. Gralka,

It worked with followings:

var EvenOdd = function (a, b, c){
if(a % 2 == 0){
    return (console.log("even"))
}
else {
    return (console.log("odd"))
}
}

EvenOdd (3, 6, 9);
J.T. Gralka
J.T. Gralka
20,126 Points

Remember that you want the function to return the strings and not necessarily log them in the console. Secondly, you want to call the function by passing through three arguments; for example:

EvenOdd(2, 6, 9);

I can't help but feel there was supposed to be something more to this challenge, why does it want us to use 3 arguments? Did the author forget what they were doing halfway?

Adam Menczykowski
Adam Menczykowski
2,319 Points

Yes, why do we have to pass 3 arguments when they are not used?

Ojong Obasi
Ojong Obasi
6,561 Points

var numberType = function(a , b, c) { if (a % 2 == 0) { console.log("Even"); } else { console.log("Odd"); } } numberType(5 , 3 , 5);

This will console log "Odd" because "a" in the numberType(5 , 3 , 5); is an odd number. If you change "a" to let say 4, it will console log "Even"

var evenOdd = function(a,b,c) { console.log( a%2 ? 'odd' : 'even')
}

Tibor Ruzinyi
Tibor Ruzinyi
17,968 Points
var oddEven = function(a,b,c){
    return a = a + b +c;
}

var result  = oddEven(3,2,4);

if (result % 2 == 0 ) {
    console.log("even");
}else{
    console.log("odd");
};
Nigel Horton
Nigel Horton
5,962 Points

var i = function (a,b,c) { return a +b + c; }

var x = i(2,3,3);

if(x%2==0){ console.log("even");
}else { console.log("odd"); }

I think this is saying: variable i is a function with parameters a, b, and c and will return value of a +b + c variable x will execute the i function substituting (a,b,c) with (2,3,3) and will return the value if x value divided by 2 has a remainder of 0 it will be true then execute console.log ("even") if x value divided by 2 has a remainder that is not 0 it will be false then execute console.log ("odd")