The Parity Pendulum

EasyAcc. 97.4%
+15 XP 5

Swinging the Logic

The Modulo (%) operator finds the remainder. When you divide by 2, a remainder of 0 means the number is even. You can combine this mathematical trick with a Ternary Operator to create a lightning-fast categorization system.

The Assignment

Your function receives a parameter named n.

  1. Declare a variable named parity.
  2. Use the ternary operator to assign a value to parity:
    • If n % 2 === 0, assign "Even".
    • Otherwise, assign "Odd".
  3. Print the resulting value of parity.

01EXAMPLE 1

Inputn = 14
OutputLogs: "Even"

Explanation: 14 divided by 2 has no remainder.

02EXAMPLE 2

Inputn = 7
OutputLogs: "Odd"

Explanation: 7 divided by 2 has a remainder of 1.

Constraints

  • Use the modulo operator (%).
  • Use the ternary operator (? :).
  • Log the value of the parity variable.
Control FlowConditionalsOperators
JavaScript
Loading...
4 Hidden

Input Arguments

n14

Expected Output

Even

Click RUN to test your solution