Andrew Carr10,979 Points
Why if function does not work.
I tried using the following code but it doesn't seem to complete the code challenge. I understand "answer = answer.to_i if kind == "number"' is simpler, but how is my code inherently different?
def parse_answer(answer, kind="string") if answer.kind == "number" answer = answer.to_i end return answer end
Jeff Jacobson-Swartfager15,413 Points
You are comparing the value in the
kind method on
answer to the string
"number". The answer object that is being passed into
parse_answer may not have a
The construction of the
parse_answer method is looking to get at least 1 required argument (
answer) and 1 optional argument (
You need to test the value of the optional
kind argument to pass.