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 trialMateusz Hyla
4,658 PointsI dont know why my code cant pass challange. Its about hashes and arrays
Hi
I write a code you can see in this post. I completely don't understand text of task in this challange. Maybe because I am not native English or maybe there are mistakes in this text.
I tried to do what I could but there is still error. I dont understand this error because its written that contact['name'] hash doesnt have return value of method get_name.
I made a localhost test and it has that value.
It would be a much much better if Treehouse would construct more clear task texts and if there would be an error it could exactly say whats wrong becase now it is like 1=2 for me.
Can anyone help please in solving that :-).
Cheers
contact_list = []
contact = {"name" => "", "phone_number" => "" }
def get_name
return "ABC"
end
item = get_name
contact['name'] = item
3 Answers
William Li
Courses Plus Student 26,868 PointsAssign 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.
I believe that the challenge description is a bit ambiguous here; but all it asks you to do is to assign the return value of get_name()
method call to the "name" key, assuming get_name()
is already defined.
contact_list = []
contact = {"name" => get_name(), "phone_number" => "" }
That's all for this part of the challenge. Hope it helps.
Mateusz Hyla
4,658 PointsHey
Thank you William. Almost always the simples solutions are the best and I forgot about that. But still I think Treehouse could write that challange more understandable :p.
Big thanks for help.
Cheers ^_^
Anterrio Howard
2,625 PointsHere is the answer:
contact['phone_number'] = get_phone_number