Devin Scheu66,189 Points
Question: Fill out the parse_answer method to return the answer passed in. If the kind is number, convert it to an integer using the to_i method before returning it.
def parse_answer(answer, kind="string") if answer = kind return answer else return answer.to_i end end
Sean T. UnwinTreehouse Moderator 28,388 Points
You can do this in one line code, aside from the
return answer statement.
The answer to the challenge is essentially given in the preceding video at around the 2min mark to 2min25sec, or in other words, the last 2 lines of the
ask method in the video. :)
J VPro Student 16,607 Points
That's a hard one just because it has to be written in a certain way.
def parse_answer(answer, kind="string") answer = answer.to_i if kind == "number" return answer end
Anand Mohan DuddellaPro Student 8,263 Points
try without answer = gets.chomp and try with giving == (kind == "number")
Anu Sandhu2,719 Points
I have tried the code below, but am not passing the challenge. Any suggestions?
def parse_answer(answer, kind="string") answer = gets.chomp answer = answer.to_i if kind= "number" return answer end