0

Still doing the Codecademy training for JavaScript and I've hit a road block.

Here's the code:

var isEven = function(number) {
if (isEven % 2 === 0) {
  return true;
} else {
  return false;
}
};

isEven(2);

So I'm referencing the variable "isEven." Then, I'm telling it to check the number and cross-check it with the modulo to check the remainder against 2 to find out if it's even. If it is, for example, 2 like in the example it should return a remainder of zero, therefore the if is true and it returns true. But it returns false every time. There's no warning messages in the code but when I hit save and it checks it it gives me this message:

"Oops, try again. Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even."

5
  • 2
    if (isEven % 2 === 0) { .. change isEven to number Commented Feb 27, 2014 at 21:03
  • You are trying to do a modulo on a function reference here – which of course makes no sense at all. The parameter you are passing into the function is called number Commented Feb 27, 2014 at 21:03
  • Take a second and look at what isEven really is defined to be. Commented Feb 27, 2014 at 21:05
  • 1
    It should be function isEven(number){ return number % 2 === 0; } Commented Feb 27, 2014 at 21:05
  • @Derek朕會功夫 Yeah, every programmer would do that, but that's not what Codecademy is about (at least not the basic JavaScript courses). Commented Feb 27, 2014 at 21:12

4 Answers 4

6

I think you had the wrong variable name:

var isEven = function(number) {
    if (number % 2 === 0) {
        return true;
    } 
    return false;
    
};

isEven(2);
Sign up to request clarification or add additional context in comments.

Comments

5

you could also do:

var isEven = function(number) {
    return number % 2 === 0
};

Comments

0

Your function and variable have the same name. Name the function or the variable differently and it will work.

Comments

0

You need change varible isEven to number, like:

var isEven = function(number) {
if (number % 2 === 0) {
return true;
} else {
return false;
}
};

isEven(2);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.