Created
February 22, 2016 02:57
-
-
Save cyberrob-zz/8c3530f9eb1069d57e69 to your computer and use it in GitHub Desktop.
udemy_ror_course_assignment_area_code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
city_codes = { | |
'taipei' => 100, | |
'new york'=> 200, | |
'new orleans' => 300, | |
'houston' => 400, | |
'los angles' => 500, | |
'chicago' => 600, | |
'washington' => 700, | |
'memphis' => 800, | |
'london' => 900, | |
'dallas' => 1000 | |
} | |
# method to display city name | |
def displayAvailableCity(cities) | |
availableCities = '' | |
cities.each { | |
|key, value| availableCities += key + ', ' | |
} | |
puts availableCities | |
end | |
# method to get area code | |
def getCityCode(city, cities) | |
code = 0 | |
cities.each { | |
|key, value| code = value if key.include? city | |
} | |
puts "You choose #{city} whose code is #{code}" | |
end | |
def firstQuestion() | |
puts "Do you want to check up city code?(Y/N)" | |
answer = gets.chomp | |
return answer | |
end | |
answer = firstQuestion() | |
loop do | |
if not answer.include? 'Y' | |
puts "Bye!" | |
break | |
end | |
puts "Type in one of these cities #{displayAvailableCity(city_codes)}" | |
city = gets.chomp | |
puts "#{getCityCode(city, city_codes)} bye!" | |
break | |
#answer = firstQuestion() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment