Check number is Odd or Even [JS] var oddoreven = function n = false, type = odd var time = n ? new Date.getDay : Numbern; if /^-0,1\d/.testtime alertarguments i
var oddoreven = function (n = false, type = 'odd') {
var time = !n ? new Date().getDay() : Number(n);
if (!/^-{0,1}\d+$/.test(time)){
alert('arguments is not number, please remove quote');
return;
}
hasil = time % 2;
return hasil == (type == ('odd' || 'ganjil') ? 1 : 0);
}
Test
document.write('isOdd / Ganjil : ' + oddoreven(false, 'odd'));
document.write('<br/>');
document.write('isEven / Genap : '+oddoreven(false, 'even'));
Output
isOdd / Ganjil : true
isEven / Genap : false