jeudi 18 avril 2019

How to identify the number 0 as zero and not as an even number

Complete noob. Just wanna log the number 0 as zero and not even.

var num= 0

if (num % 2 !==0){

    console.log("odd")

} else if (num %2 ===0){

    console.log("even")

} else if (num == 0){

    console.log("zero")

} else {

    console.log("error")
}

I expect the output to be "zero" but it keeps logging it as even.

Aucun commentaire:

Enregistrer un commentaire