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 trialClifford Stiber
1,343 PointsNot sure why (answer, kind="string") is required if we add the line answer = answer.to_s if kind = "string", seems redun
Can someone please clarify this for me? Not sure why (answer, kind="string") is required if we add the line answer = answer.to_s if kind = "string", seems redundant?
def parse_answer(answer, kind="string") answer = answer.to_s if kind=="string" answer = answer.to_i if kind=="number" return answer end
def parse_answer(answer, kind="string")
end
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! This is tricky. It's because we could call the method like this:
parse_answer(my_answer)
And you'll notice we send off one argument... not two. When we do this then it will automatically set kind equal to "string" as the default value. But we could call it like this:
x = "number"
parse_answer(my_answer, x)
At this point kind will now be equal to "number" instead of "string". The kind="string" is just there to tell us what to default to if nothing is passed in. Hope this helps!
Clifford Stiber
1,343 PointsThanks.. Really appreciate the speedy reply.