Code is OK but still won't pass me
I have to fill out the
parse_answer method to return the
answer passed in. If the
number, convert it to an integer using the
to_i method before returning it.
What am I doing wrong, I've also tested it in my Console and it runs ok...
I can't seem to understand the requirement, it's a little vague, return what ?? The
answer or the
def parse_answer(answer, kind="string") print "Your answer is: " answer = gets.chomp answer = answer.to_i if kind == "number" return answer end puts parse_answer(32)
Justin HornerTreehouse Guest Teacher
The challenge is assuming that the answer has already been provided from the console, it just needs to parse the answer for the given kind.
You can remove the puts and chomp lines and simplify the function to the following.
def parse_answer(answer, kind="string") answer = answer.to_i if kind == "number" answer end
I hope this helps.
Travis Granger2,745 Points
I don't understand why we don't need the "return" between lines 2 and 3 in @Justin's code.. would appreciate an explanation.