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

Christopher Kemp
Christopher Kemp
3,446 Points

parse_answer

When I try to run this, all I get is the "Bummer: Try again!" message and so I am not even sure where I am going wrong because i can't preview what the code is doing either.

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

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Couple issues with your code.

  1. answer was pass-in as the method argument, you do NOT need to assign get.chomp to answer.
  2. puts statement doesn't generate any return value for the method.
def parse_answer(answer, kind="string")
  if kind=='number'
    answer = answer.to_i
  end
  answer
end

this should do it.

Christopher Kemp
Christopher Kemp
3,446 Points

Thank you very much! I guess I just was overthinking it.