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

Rafael Herazo
Rafael Herazo
18,114 Points

I honestly don't understand the instructions. Please help

Assign the value of the key name to the return value of the method get_name() in the contact hash. Assume that get_name() returns a string.

contact_list = []

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

I've tried everything!!

This is what I have

def get_name() contact = {"name" => "", "phone_number" => "" } contact["name"] = ??? return contact end

I only get Bummer! Try again.

This is frustrating!

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Rafael,

The challenge wants you to assign the returned value of get_name() to the key of name. So, you have everything pretty much right, except where you have an empty string ("") for name, you need to call the get_name() function instead.

contact = {"name" => get_name(), "phone_number" => "" }

Hope this helps. Keep Coding! :)

Rafael Herazo
Rafael Herazo
18,114 Points

Thanks for your help, I still get an error message because I don't know what it means by Assume that get_name() returns a string

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

The code posted above will pass Task 1.

As for, assume that get_name ... ... Sometimes the challenges, instead of presenting all the code, will have you 'imagine' that there is a function called get_name() and that a string has been passed as the argument (therefore returning a string) and then wants you to write the remaining code base on all these assumptions.

In this case, imagine that instead of passing in an actual string, you are passing in the function with a string as an argument, and the only purpose of the function is to return the argument. It would be the same as contact = {"name" => get_name('Jason'), "phone_number" => "" }

I hope this starts to make sense for you. :)

Rafael Herazo
Rafael Herazo
18,114 Points

Thanks a lot, I was just writing too much code. Thanks again!