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
PRO
William Li
Pro Student 26,692 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.