Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 637 Bytes

get_planet_name_by_id.md

File metadata and controls

33 lines (28 loc) · 637 Bytes

Description

The function is not returning the correct values. Can you figure out why?

Example (Input --> Output ):

3 --> "Earth"

My Solution

def get_planet_name(id)
  case id
  when 1 then "Mercury"
  when 2 then "Venus"
  when 3 then "Earth"
  when 4 then "Mars"
  when 5 then "Jupiter"
  when 6 then "Saturn"
  when 7 then "Uranus"
  when 8 then "Neptune"
  end
end

Better/Alternative solution from Codewars

def get_planet_name(id)
  %w[0 Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune][id]
end