# Set up the dataset - hash
dial_book = {
"newyork" => "212",
"newbrunswick" => "732",
"edison" => "908",
"plainsboro" => "609",
"sanfrancisco" => "301",
"miami" => "305",
"paloalto" => "650",
"evanston" => "847",
"orlando" => "407",
"lancaster" => "717"
}
# Define the methods: Get city names from the hash
def get_city_names(dial_book)
puts "Which city do you want the area code for?"
dial_book.each {|key, value| puts key}
end
# Define the method: Get area code based on given hash and key
def get_area_code (dial_book)
puts "Enter your selection"
city_selection = gets.chomp
dial_book.each do |key, value|
if city_selection == key
puts "The area code for #{key} is #{value}"
end
end
end
# Loop flow
loop do
puts "Do you want to look up a city's area code? (Y/N)"
initiation_answer = gets.chomp.downcase
break if initiation_answer != "y"
get_city_names(dial_book)
get_area_code (dial_book)
end