Zero-Logic Toggle
MediumAcc. 85.4%
+35 XP 10
Mathematical Toggling
In UI development, we often toggle between a state of 0 (off) and 1 (on). While you could use an if statement, using simple math is much faster and more elegant.
The Assignment
Your function receives a parameter state which is always either 0 or 1.
- If the input is
0, return1. - If the input is
1, return0. - Requirement: Do not use any comparison symbols (
==,===,>, etc.) oriflogic. Solve it with Math.
01EXAMPLE 1
Input
state = 0Output
1Explanation: The state is flipped to 1.
Constraints
- Solve using arithmetic (subtraction or modulo).
- No comparison operators allowed.
MathLogicMastery
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
state0
Expected Output
1
Click RUN to test your solution