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

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,323 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!