JavaScriptで奇数・偶数を判定する

created 2021/02/09updated 2021/02/09

普通

js
let number = 2 if((number%2) == 0) { console.log("偶数(even)") } else { console.log("奇数(odd)") }

0以上

js
let number = 0 if(number == 0) { console.log("zero") } else if ((number%2) == 0) { console.log("偶数(even)") } else { console.log("奇数(odd)") }