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.

  1. If the input is 0, return 1.
  2. If the input is 1, return 0.
  3. Requirement: Do not use any comparison symbols (==, ===, >, etc.) or if logic. Solve it with Math.

01EXAMPLE 1

Inputstate = 0
Output1

Explanation: The state is flipped to 1.

Constraints

  • Solve using arithmetic (subtraction or modulo).
  • No comparison operators allowed.
MathLogicMastery
JavaScript
Loading...
2 Hidden

Input Arguments

state0

Expected Output

1

Click RUN to test your solution