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 trialY K
3,390 PointsExtra 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
3,390 PointsThanks 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
20,126 PointsRemember 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);
Thomas MacFarlane
2,430 PointsI 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
2,319 PointsYes, why do we have to pass 3 arguments when they are not used?
Ojong Obasi
6,561 Pointsvar 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"
ogechi
Courses Plus Student 3,431 Pointsvar evenOdd = function(a,b,c) {
console.log( a%2 ? 'odd' : 'even')
}
Tibor Ruzinyi
17,968 Pointsvar 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
5,962 Pointsvar 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")