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

Joshua Atteberry
Joshua Atteberry
6,250 Points

Getting an error on "Build a simple contact list" challenge 1 of 1

The error is a "no such file or dir" error, which I'm guessing is generic for my code doesn't work.

It seems as if the code should work.

I get the input and assign it to the variable "answer".

I convert it to an integer with to_i.

And then I return it.

I tried submitting it with and without the puts statement outside the block. Nothing seems to work.

I also tried making the "answer" variable different from the "answer" argument as it is in the video example. This didn't work either.

Any help is much appreciated!

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

answer = parse_answer(" ")
puts answer

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You have more in your code than the challenge wants you to. This is the minimum passing code:

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

I'm not sure where the chomp came from and why you added things after the method. But you had the passing code there :)

Nicholas Meyers
Nicholas Meyers
2,512 Points

I had the same problem as Joshua. I think the reason I got confused, because Jason in his video used the line "answer = gets.chomp", which is why I tried to have it in my code. I think our problem is that we tried to over complicate the challenge.

Thank you Maciej for the help!