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 trialMichael Speight
4,536 Pointshelp! i do not understand the question fully
def parse_answer(answer, kind="string") answer = gets answer = answer.to_i if kind == "number"
return answer
end
code i have tried
def parse_answer(answer, kind="string")
answer = gets
answer = answer.to_i if kind == "number"
return answer
end
2 Answers
Tom Sager
18,987 PointsThe value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.
Jerome Doyle
8,855 Points"answer = gets" will get you input along with a default type of string. for example, when you assign "parse_answer("whatever") " it actually means ("whatever", "string") but, if you want to type a number parse_answer("1") the default type of the "1" is a string not a integer. however, if you give a description like("1","number")
it will convert "1" to a integer 1
Tom Sager
18,987 PointsTom Sager
18,987 PointsThe value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.