Check number is Odd or Even [JS]

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

Comments

Popular posts from this blog

Find Backlink From Google Dork

List of weapon buff materials, effects and how it can be durango wild lands

Install deb package via Termux