vendredi 9 janvier 2015

In Ruby trying to use .each do on a given hash

This is what I am attempting to do:


Write a method that takes the hash and prints if city is large (more than 100,000) or small (otherwise). Printing something like: Vancouver is a large city.


Here is my provided hash:



bc_cities_population = {vancouver: 2135201, victoria: 316327, abbotsford: 149855, kelowna: 141767, nanaimo: 88799, white_rock: 82368, kamloops: 73472, chilliwack: 66382 }


Here is my code:



bc_cities_population = {vancouver: 2135201, victoria: 316327, abbotsford: 149855, kelowna: 141767, nanaimo: 88799, white_rock: 82368, kamloops: 73472, chilliwack: 66382 }

bc_cities_population.each do |city, population|
if population > 100,000
puts "#{city} is a big ol city!"
elsif
puts "#{city}city is a tiny ol town"
end
end


Thanks for your help..


Edit: Here is the error I am receiving..



ruby big_small_city.rb
big_small_city.rb:1: syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '('
...er: 2135201, victoria: 316327, abbotsford: 149855, kelowna...


Edit2:


this is my revised code which i am still unsure why is not working..



bc_cities_population = {vancouver: 2135201, victoria: 316327, abbotsford: 149855, kelowna: 141767, nanaimo: 88799, white_rock: 82368, kamloops: 73472, chilliwack: 66382 }

bc_cities_population.each do |city, population|
if population > 100_000
puts "#{city} is a big ol city!"
else
puts "#{city} is a tiny ol town"
end
end

Aucun commentaire:

Enregistrer un commentaire