Files
30-seconds-of-code/snippets/even-or-odd-number.md
2017-12-12 07:11:37 -05:00

242 B

Even or odd number

Use Math.abs() to extend logic to negative numbers, check using the modulo (%) operator. Return true if the number is even, false if the number is odd.

const isEven = num => Math.abs(num) % 2 === 0;