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 trial

Ruby Ruby Loops Build a Simple Contact List Methods That Return a Value

Tyler Walker
Tyler Walker
609 Points

I didn't feel prepared to answer this question. I am also not entirely sure what they are asking. Skipped it

This is the second excercise in this course that has felt out of order.

I have been super comfortable with every exercise in TeamTree house until this one, and one earlier. (will go back and comment)

ask.rb
def parse_answer(answer, kind="string")
  answer = gets.chomp
  answer = answer.to_i if kind == "number"
  return answer
end
answer = gets.chomp
parse_answer(answer)

1 Answer

Mohamed Fouda
PLUS
Mohamed Fouda
Courses Plus Student 6,202 Points

To understand this example First parse_answer method take one argument which is answer and we declare the aswer input kind to our method to. be string by defult so any input to our parse_answer will be recognized as string kind

But if our parse_method declared input with kind number only it must use answer.to_i to transform it from kind string to kind number

That’s very useful as it gives you flexibility to deal with strings which can include characters and or numbers but if you got input only in numbers you can transform it from string to into integers