in Javascript

How To Check Number Is Odd Or Even

Education Here is a quick little snippet which can prove to be quite useful. This snippet will check to see if a number is odd or even. ## In Javascript


function checkEven(val){
     return (val%2 == 0);
}

val = 3;

if(checkEven(val)){
    alert("Number is even");
} else {
    alert("Number is odd");
]

In PHP

In PHP it's actually exactly the same just fix the variables.


function checkEven($val){
     return ($val%2 == 0);
}

$val = 3;

if(checkEven($val)){
    echo "Number is even";
} else {
    echo "Number is odd";
]

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email