Files
30-seconds-of-code/snippets/even-or-odd-number.md
Angelos Chalaris 43f8529cb9 Added samples
2017-12-12 17:50:08 +02:00

10 lines
264 B
Markdown

### 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.
```js
const isEven = num => Math.abs(num) % 2 === 0;
// isEven(3) -> false
```