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

jakefish
jakefish
7,961 Points

methods that return a value

not quite sure what they're looking for here...

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Well no matter what we need to return the answer. But we also need to look if the kind variable is equal to "number". If it is, then we need to convert it to a number before we return it. But your code is trying to compare the kind to a variable named number... not the string "number". Also, an if block needs its own end statement. Take a look:

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

Here we have our function that accepts an answer and a kind. The default of kind is "string". But if we were to send in a kind of "number", then the code in the if statement would execute. In this case, it converts the answer to a number. And regardless of what else happens, we always return the answer. Hope this helps! :sparkles: