The Signal Decoder

EasyAcc. 96.1%
+15 XP 5

The Decoder Array

Numeric codes like 404 or 400 are efficient for machines, but humans need words. A switch statement is the perfect tool for building a lookup table that "decodes" these signals.

The Assignment

Your function receives a parameter named errorType.

  1. Declare a variable named errorMessage.
  2. Use a switch statement on errorType:
    • If errorType is 400, assign "Bad Request" to errorMessage.
    • If errorType is 404, assign "Not Found" to errorMessage.
    • Otherwise (default), assign "Unknown Error" to errorMessage.
  3. Return the errorMessage.

01EXAMPLE 1

InputerrorType = 404
Output"Not Found"

Explanation: Code 404 matches the second case.

02EXAMPLE 2

InputerrorType = 500
Output"Unknown Error"

Explanation: 500 hits the default case.

Constraints

  • Use a switch statement.
  • Return the decoded message as a string.
Control FlowConditionalsFundamentals
JavaScript
Loading...
4 Hidden

Input Arguments

errorType404

Expected Output

Not Found

Click RUN to test your solution