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.

  1. Declare a variable named medal.
  2. Use a chained ternary operator to assign values:
    • If rank is 1, medal should be "Gold"
    • If rank is 2, medal should be "Silver"
    • For all other ranks, medal should be "Bronze"
  3. Return the string: "medal : [value]"

01EXAMPLE 1

Inputrank = 1
Output"medal : Gold"

Explanation: Highest rank gets Gold.

02EXAMPLE 2

Inputrank = 3
Output"medal : Bronze"

Explanation: Anything below 2 gets Bronze.

Constraints

  • Use a chained ternary (? :) expression.
  • Return the result in the "medal : [value]" format.
Control FlowConditionalsOperators
JavaScript
Loading...
3 Hidden

Input Arguments

rank1

Expected Output

medal : Gold

Click RUN to test your solution