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 Part 2: Adding Contacts

Brandon Keene
Brandon Keene
7,217 Points

Missing lines in Teacher's Notes Code Sample

Jason Seifer

Just a quick note, the code samples present in the Teacher's Notes for this video are missing two lines, the absence of which results in an infinite loop.

The code sample below is what actually gets typed on-screen, but I have commented out the lines which are not present in the code samples.

def add_contact
  contact = {"name" => "", "phone_numbers" => []}
  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

@Brandon, good spot! Without that return statement in the add_contact method or the "Add another?", there's no gentle program exit and the entries to the contact array are nil.

If you're interested, check out my todo_cli program and see if you can't find any oddities. Any feedback is much appreciated.

Brandon Keene
Brandon Keene
7,217 Points

Emmanuel Obi Thanks! I appreciate that you place enough faith in my watchful eye to look at your code, and I had a look. Nothing looks out of place to me, but I'd be misleading you if I told you I felt like that actually means much. I'm still far too novice to feel truly equipped for such a critique. Good luck with the project!