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
May Loh
5,213 PointsIntroduction to Programming Extra Credit Exercise - Function
Anyone knows what to do with b and c, for the Introduction to Programming Extra Credit exercise? Rather stuck with these two.
This 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 this is how far I've come:
var sayABC = function (a, b, c) {
if (a % 2 == 0) {
document.write ("even");
} else {
document.write ("odd");
}
}
2 Answers
May Loh
5,213 PointsThis worked for me but can anyone recommend a better way?
var a = parseInt (prompt ("Enter a number for A"), 10);
var b = parseInt (prompt ("Enter a number for B"), 10);
var c = parseInt (prompt ("Enter a number for C"), 10);
sayABC(a, b, c);
function sayABC (a, b, c) {
if ((a + b + c) % 2 == 0) {
document.write ("even");
} else {
document.write ("odd");
}
}
Drew Schott
8,484 PointsMaybe this? It could be an instance where a is an input, but you must include it in the equation to come out with the correct answer. You can really interpret it how you want, they just want you to see you can have more than 2 arguments.
var sayABC = function (a(apples in the basket), b(bad apples take out of the basket), c(collected apples added to the basket today)) {
a = (a + c) - b;
if (a % 2 == 0) {
return "even - basket is good, you can stop";
}
else
return "odd - basket is not right, keep picking";
}
}