Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

4Ctech Admin
4Ctech Admin
5,062 Points

Ruby: Stage 3: Build A Simple Contact List Challenge not working

I don't get why this code isn't working. I tried a few things that didn't work and then just used the same code that Jason Seifer used in the video. I don't really get an error. The response is just "Bummer! Try again!"

contact_list.rb
contact_list = [
  {"name" => "Jason", "phone_number" => "123"},
  {"name" => "Nick", "phone_number" => "456"}
]

contact_list.each do |contact|
  puts "Name: #{contact["name"]}"
  if contact["phone_number"].size > 0
    contact["phone_number"].each do |number|
      puts "Phone Number : #{contact["phone_number"]}"
    end
  end
Maurice Tafolla- Cunningham
Maurice Tafolla- Cunningham
7,708 Points

My code looks exactly the same aside from my block choice.

It's frustrating when these challenges are deceptively simple.

I had to come here to the forum and see why I was getting the same error, so thanks for asking this question and helping me out!

3 Answers

Hi,

They require only values without additional information, just simple like this without complicated. :-)

contact_list = [
  {"name" => "Jason", "phone_number" => "123"},
  {"name" => "Nick", "phone_number" => "456"}
]

contact_list.each do |contact|
  puts contact["name"]
  puts contact["phone_number"]
end

Hope that helps.

It's frustrating that most of the other answers allow things like

puts "Name: #{name}" and this one doesn't allow for anything extra.

sergiu cozma
sergiu cozma
14,774 Points

Why doesn't this code works?

contact_list = [
  {"name" => "Jason", "phone_number" => "123"},
  {"name" => "Nick", "phone_number" => "456"}
]

contact_list.each do |contact|
  contact.each_value do |v|
    puts v
  end
end