The Olympic Oracle
MediumAcc. 88.4%
+25 XP 10
Logic Chains
While a single ternary handles a binary choice, you can "chain" them to handle three or more outcomes. This is done by placing another ternary inside the "else" part of the first. It reads like an if-else if-else but fits in a single powerful line.
The Assignment
Your function receives a parameter named rank.
- Declare a variable named
medal. - Use a chained ternary operator to assign values:
- If
rankis 1,medalshould be "Gold" - If
rankis 2,medalshould be "Silver" - For all other ranks,
medalshould be "Bronze"
- If
- Return the string: "medal : [value]"
01EXAMPLE 1
Input
rank = 1Output
"medal : Gold"Explanation: Highest rank gets Gold.
02EXAMPLE 2
Input
rank = 3Output
"medal : Bronze"Explanation: Anything below 2 gets Bronze.
Constraints
- Use a chained ternary (? :) expression.
- Return the result in the "medal : [value]" format.
Control FlowConditionalsOperators
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
rank1
Expected Output
medal : Gold
Click RUN to test your solution