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 Assigning Hash Values From Methods

Christina Colbert
Christina Colbert
17,332 Points

Struggling with this Ruby code challenge

I have been working on this code challenge for a while now. I've tried different options, and attached is my latest iteration. I have Ruby installed on my computer, so I've run it on the command prompt and it works, but it must not meet the criteria for this challenge. Any feedback would be appreciated.

contact.rb
contact_list = []
$contact = {"name" => "", "phone_numbers" => []}

def ask(question, kind="string") 
  print question + " "
  answer = gets.chomp
  answer = answer.to_i if kind == "number"
  return answer
end

def set_name
    $contact["name"] = ask("What name do you want to enter?")
end

def get_name
  return $contact["name"]
end

set_name
puts get_name

3 Answers

Kevin Naegele
Kevin Naegele
10,868 Points

I think your on this challenge?

contact_list = []

contact = {"name" => "", "phone_number" => "" }

they want use the method get_name()

contact_list = []

contact = {"name" => get_name(), "phone_number" => "" }
Christina Colbert
Christina Colbert
17,332 Points

I should specify that I am still on step 1 of the challenge, which needs to return the value of name through the get_name method.

Christina Colbert
Christina Colbert
17,332 Points

That worked - thanks! I was making it harder than it needed to be.