Ruby Ruby Loops Build a Simple Contact List Methods That Return a Value

Carl Smith
Carl Smith
8,085 Points

Having trouble with this program

Not sure what I'm doing wrong here, just getting a "Bummer, tray again" error.

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

1 Answer

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,068 Points

You have to check if the "kind" variable is a number before you convert the "answer" variable to an integer, you could do it, like this:

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

I hope that helps a little bit.

Carl Smith
Carl Smith
8,085 Points

Thank you, I was a little confused on the way to do it. I tried copying what was done in the video before this. Was unclear on how to perform. this clears it up. Thank you again!