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 trialNick Evershed
6,429 PointsCode not working
undefined method 'push' line 17?
def ask(question, kind="string")
print question + " "
answer = gets.chomp
answer = answer.to_i if kind == "number"
return answer
end
def add_contact
contact = {"name" => "", "phone_number" => []}
contact["name"] = ask("What is the person's name?")
answer = ""
while answer != "n"
answer = ask("Do you want to add a phone number? (y/n)")
if answer == "y"
phone = ask("Enter a phone number:")
contact["phone_numbers"].push(phone)
end
end
return contact
end
contact_list = []
answer = ""
while answer != "n"
contact_list.push(add_contact())
answer = ask("Add another? (y/n)")
end
1 Answer
Steve Hunter
57,712 PointsHi there,
Your array is called phone_number
but you have used .push
on phone_numbers
. Lose the 's
' at the end and that should work.
Good luck,
Steve.
Nick Evershed
6,429 PointsNick Evershed
6,429 PointsDammit it was that simple, thanks!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem!