Ruby Ruby Loops Build a Simple Contact List Hash and Array Iteration

Manish Giri
Manish Giri
16,265 Points

Not passing checks for printing value of hash keys

The challenge asks -

Using the each method, iterate over the contact_list array. Assign each array item to the local variable contact in the block and print out the value of the name and phone_number keys.

My code is attached. I also tried another way, both works in Repl.it - https://repl.it/EXBV/0

Not sure what's wrong here.

contact_list.rb
contact_list = [
  {"name" => "Jason", "phone_number" => "123"},
  {"name" => "Nick", "phone_number" => "456"}
]
contact_list.each { |contact| contact.each {|k,v| print v}}

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,429 Points

OK, so the challenge is asking you to print only name and phone number values. Your code is more universal and would print all the values that might find their way into the hash (for example, if you add "age" => 21, this would be printed as well). You need to explicitly print the selected key values, nothing more:

puts contact['name']
puts contact['phone_number']
Manish Giri
Manish Giri
16,265 Points

Ah, understood it now. Thank You!