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

Jordan Hammond
Jordan Hammond
2,278 Points

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

Can someone help me understand why this would return as "Uncaught TypeError: undefined is not a function "? It's from the extra credit question. It did display "odd" though so that's good.

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

var x = practice(1, 2, 3)

x()

Thanks!

2 Answers

Lush Sleutsky
Lush Sleutsky
14,044 Points

Your code runs fine when I run it, with the exception of

x()

at the end there. That is not needed.

And also, you did take some extra steps... You don't need

var x = practice(1, 2, 3)

as you could just have called the function like so:

practice(1, 2, 3)

Also, try to change this line to:

if (a%2 === 0)

Three equals might make it work in whatever you're testing it, but I ran it the just the way you had it in the Chrome console, and the results were fine...

Hi Jordan,

The function practice() doesn't return anything, it just outputs to the console. So essentially the statement, var x = practice(1, 2, 3) means x equals nothing returned.

Jeff