js check if number is divisible by 2 1

js check if number is divisible by 2

if (variable % 2 === 0) {
  console.log("Even")
} else {
 console.log("Odd") 
}

Here is what the above code is Doing:
1. We’re creating a variable called variable and assigning it a value of 2.
2. We’re using the modulo operator to check if the value of variable is divisible by 2.
3. If the value of variable is divisible by 2, we’re printing “Even” to the console.
4. If the value of variable is not divisible by 2, we’re printing “Odd” to the console.

Similar Posts