I came across http://rindovincent.blogspot.com/p/javascript.html where there was a simple Javascript program to find whether the number is odd or even. I am pasting the same code with permission here.
var n = prompt(“Enter a number to find odd or even”, “Type your number here”); n = parseInt(n); if (isNaN(n)) { alert(“Please Enter a Number”); } else if (n == 0) { alert(“The number is zero”); } else if (n%2) { alert(“The number is odd”); } else { alert(“The number is even”); }
Why not just
function isEven(value) {
return (value%2 == 0);
}
And the PHP version only needs an extra dollar sign:
function isEven($int){
return ($int%2 == 0);
}
In these times, I can assume most webdevvers use a javascript library like jQuery or similar. These libraries have functions like isEven built in.
For those who don’t use such libraries: great snippet ;)
I came across http://rindovincent.blogspot.com/p/javascript.html where there was a simple Javascript program to find whether the number is odd or even. I am pasting the same code with permission here.
var n = prompt(“Enter a number to find odd or even”, “Type your number here”);
n = parseInt(n);
if (isNaN(n))
{
alert(“Please Enter a Number”);
}
else if (n == 0)
{
alert(“The number is zero”);
}
else if (n%2)
{
alert(“The number is odd”);
}
else
{
alert(“The number is even”);
}
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.