-1

I'm trying to write a function that checks whether a value is odd or even, but it isn't quite working as it should, or rather, at all.

The code I got was from this question.

        function isEven(value) {
            if (value % 2 == 0) {
                return true;
                console.log("True");
            }
            else {
                return false;
                console.log("False");
            }
            console.log(value);
        }

        isEven(3);

I get no errors in the browser's console, but it also does not log True, False, or value.

Note: I will also accept jQuery solutions, but would prefer Javascript.

Community
  • 1
  • 1

2 Answers2

2

You are returning before logging. Anything after return will not be executed.

return after logging

 function isEven(value) {
   if (value % 2 == 0) {
     console.log("True");
     return true;
   } else {
     console.log("False");
     return false;
   }
 }

 isEven(3);
AmmarCSE
  • 29,061
  • 5
  • 39
  • 52
0

Ensure value is an integer first by parsing it with

parseInt(value)
omikes
  • 7,248
  • 8
  • 36
  • 47