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.
- Declare a variable named
parity. - Use the ternary operator to assign a value to
parity:- If
n % 2 === 0, assign "Even". - Otherwise, assign "Odd".
- If
- Print the resulting value of
parity.
01EXAMPLE 1
Input
n = 14Output
Logs: "Even"Explanation: 14 divided by 2 has no remainder.
02EXAMPLE 2
Input
n = 7Output
Logs: "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
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
n14
Expected Output
Even
Click RUN to test your solution