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 Operators and Control Structures Logical Operators The Or (||) Operator

David Grimm
David Grimm
16,169 Points

Need a better error message than Bummer!

I have typed in many forms of this code. Seems like a simple fix. Have now spent a half-hour on it. I'm sure it's a simple oversight. What is it?

def valid_command?(command) if (command == "y") || (command == "yes") || (command == "Y") || (command == "YES") valid_command? = true end end

Thanks!

2 Answers

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi David Grimm,

I haven't checked the answer, but this is how I would answer this question. I might be giving you the answer, but I will explain how I got it for you.

def valid_command?(command)                               # You have this right
  if command == "y" || "yes" || "Y" || "Yes"                #  No need to write command each time
    valid_command = true                                          #  Don't need the question mark after command
  end
end

Hope this helps

David Grimm
David Grimm
16,169 Points

Thanks, John, I appreciate it. I tried it without writing command each time. The only part I didn't do was take off the ? at the end of the valid_command. Not sure why I wouldn't keep the ?.

Thanks again.

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

I think that when defining our own method, we use the '?' as convention to tell the Ruby interpreter that the method will have a boolean value (true, false etc). When calling the method within the IF statement, you don't need to use the '?' again.

This might not be right, but I think this is what I remember from the Ruby book I read.