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
Josh Pollock
8,757 PointsExtra credit for Introduction to Programming
In the functions section of the Introduction to Programming deep dive, we're given the following assignment:
"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""
For the life of me, I'm not having any luck getting this to work. I think my code is right within the function, but I can't figure out how to access the argument a.
The code I've written so far:
var evenCheck = function (a; b; c) {
if a % 2 == 0 {
return "even";
}
else {
return "odd";
}
}
Please help! I feel like I shouldn't be having so much trouble with this, and I'm feeling kind of dumb! I didn't have any trouble with Fizzbuzz earlier.
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Josh,
You need commas between your function parameters and you are also missing parentheses around your if condition.
J Scott Erickson
11,883 PointsAre you using commas or semi-colons? The code you put there has function(a; b; c) which wouldn't work.
J Scott Erickson
11,883 PointsJ Scott Erickson
11,883 PointsI missed the parens, coding in ruby too much :-p
Josh Pollock
8,757 PointsJosh Pollock
8,757 PointsGreat, thank you! Coding late at night makes for mistakes haha. I guess my question is how do I plug in a numerical value for a to get the code to run. I've tried a few different things I thought would work and nothing did. Thanks again for the help!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou could call the function like this:
evenCheck (2, 3, 5)That should return "even" because
ais even.Josh Pollock
8,757 PointsJosh Pollock
8,757 PointsThank you so much for the help, I really appreciate it. I'm glad to know my errors were just syntax!