How to check if a number is odd or even without modulus operator in JavaScript

1 Answer

0 votes
function is_even(n) { 
    return (parseInt(n / 2) * 2 === n); 
} 
  
var n = 13; 

var s = (is_even(n)) ? "Even" : "Odd"; 
 
document.write(s);
 
   
/*
run:
        
Odd
       
*/

 



answered Mar 28, 2019 by avibootz

Related questions

...