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

help! i do not understand the question fully

def parse_answer(answer, kind="string") answer = gets answer = answer.to_i if kind == "number"

return answer

end

code i have tried

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

  return answer


end
Tom Sager
Tom Sager
18,987 Points

The value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.

2 Answers

Tom Sager
Tom Sager
18,987 Points

The value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.

"answer = gets" will get you input along with a default type of string. for example, when you assign "parse_answer("whatever") " it actually means ("whatever", "string") but, if you want to type a number parse_answer("1") the default type of the "1" is a string not a integer. however, if you give a description like("1","number")

it will convert "1" to a integer 1