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

plz tell me what's going wrong with this piece of code

this is a code for making a contact list but when i run this it simply prints :get_contact and nothing else plz tell me what's going wrong with my code

i have pasted the code below:-

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

def get_contact

answer = ask("What is your name? ") contact = {"name" => "","phone number"=>[]} contact["name"] = answer answer_1 = "" while answer_1 != 'n' number = ask("Do you want to add your phone number(y/n) ")

if number == 'y' add = ask("Enter a phone number? ") contact["phone number"].push(add)

end

return contact

end contact_list = [] answer = "" while answer != 'n' contact_list.push(get_contact()) ask(Add Another?y/n) end

puts '-'*80 contact_list.each do |contact|

puts "Name: #{contact["name"]}"

if contact["phone number"].size >0 contact["phone number"].each do |phone| puts "Phone: #{phone}" puts '_'*80 end end end puts "-------\n" end

William Li
William Li
Courses Plus Student 26,868 Points

Please refer to this guide https://teamtreehouse.com/community/posting-code-to-the-forum on how to properly post code to the forum, right now the code is unreadable.