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.
- Declare a variable named
errorMessage. - Use a
switchstatement onerrorType:- If
errorTypeis 400, assign "Bad Request" toerrorMessage. - If
errorTypeis 404, assign "Not Found" toerrorMessage. - Otherwise (default), assign "Unknown Error" to
errorMessage.
- If
- Return the
errorMessage.
01EXAMPLE 1
Input
errorType = 404Output
"Not Found"Explanation: Code 404 matches the second case.
02EXAMPLE 2
Input
errorType = 500Output
"Unknown Error"Explanation: 500 hits the default case.
Constraints
- Use a switch statement.
- Return the decoded message as a string.
Control FlowConditionalsFundamentals
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
errorType404
Expected Output
Not Found
Click RUN to test your solution