Even or Odd
1/7
A number is even when it divides by 2 with no remainder. The remainder operator gives you that directly:
n % 2 === 0 // even
Watch out for negatives. In JavaScript, C++ and Java, -3 % 2 is -1, not 1. So test n % 2 === 0 for "even" instead of n % 2 === 1 for "odd". Python's % always returns a non-negative result for a positive divisor.
Bit trick. In binary the last bit of an even number is always 0, so (n & 1) === 0 also tests evenness, and it works for negative numbers in two's complement.
Logic-building habit: before coding, write out a few inputs, including 0 and negatives, and check what your expression returns for each.