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

Qiang Gong
Qiang Gong
8,209 Points

I think I'm right

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

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

2 Answers

Ari Misha
Ari Misha
19,220 Points

Hiya there! You are right but not in the context of the challenge. I felt like this challenge was pretty obscure and incomplete. But didnt took me to long to figure it out. Now whats wrong with your code? Infact nothing is wrong with your code. But challenge never said anything about capturing the user input. The function already takes answer as an argument which means it already exists. And the kind is set to "string" as default. So So yeah your function needs to return answer as a string as a default or answer as an integer if kind is an integer. Here is my code if you get stuck or confused:

def parse_answer(answer, kind="string")
   case 
     when kind == "number" then answer.to_i
     when kind then answer.to_s
   end
end
Qiang Gong
Qiang Gong
8,209 Points

Thanks for the feedback, Ari!