The Master XOR

MediumAcc. 72.4%
+40 XP 15

The Exclusive Choice

In standard logic, XOR (Exclusive OR) only returns true if exactly one of the inputs is truthy. If both are true or both are false, it returns false.

JavaScript does not have a native logical XOR operator (the ^ symbol is for bitwise operations). Your task is to build one using only ||, &&, and !.

The Assignment

Your function receives parameters a and b.

  1. Return true only if exactly one input is truthy.
  2. Return false in all other cases.

01EXAMPLE 1

Inputa = true, b = false
Outputtrue

Explanation: One is true, so XOR is true.

02EXAMPLE 2

Inputa = true, b = true
Outputfalse

Explanation: Both are true, so XOR is false.

Constraints

  • Do not use the bitwise ^ operator.
  • Return a boolean result.
LogicOperatorsMastery
JavaScript
Loading...
3 Hidden

Input Arguments

atrue
bfalse

Expected Output

true

Click RUN to test your solution