Even and Odd
We discussed the Remainder operator
(%) in the Numbers chapter. When you divide a number by two, the division remainder is either 0 or 1. This will assist you in determining whether the original number is even (divisible by two without a remainder) or odd.
For example,
// even numbers
4 % 2 // 0
10 % 2 // 0
50 % 2 // 0
// odd numbers
3 % 2 // 1
9 % 2 // 1
15 % 2 // 1
When the number is even, the division remainder by two is always 0. When the number is odd, it is 1.
In the next challenge, we'll use an if condition to determine whether the user's entered number is even or odd!