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 Methods That Return a Value

Tyler Proctor
Tyler Proctor
11,458 Points

I've compared this with code from the video and they appear to be doing the exact same thing. What am I missing?

I'm setting the answer to a string that the user enters, then converting it to an integer if it is a number, and then returning. I don't understand how this is incorrect. Does it want me to actually call the method as well?

ask.rb
def parse_answer(answer, kind="string")
  answer = gets.chomp
  answer = answer.to_i if kind == "number"
  return answer
end

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Tyler,

You're pretty much correct, except you added something the challenge didn't ask for. The value for answer is being grabbed when the function is called, so I'm not sure why you added answer = gets.chomp. If you delete that line, the code will pass the challenge.

Keep Coding! :) :dizzy:

Tyler Proctor
Tyler Proctor
11,458 Points

Thank you! I just want to make sure I understand- so you don't need the gets method to assign a value to answer because you're already assigning the value of answer when you pass a string into the parse_answer method?