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

Not Understanding the Double End or the ? in the Code Challenge

Challenge: Modify the valid_command? method to return true when passed the following values: "y", "yes", "Y", or "YES".

Although I solved this challenge correctly, I don't understand why we need to use end twice as well as I don't understand what the ? is used for...is it just part of the variable name here? Jason used .even? and .odd? in the video prior without explaining what the ? was for.

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

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

The question mark is part of the method name. It is not necessary but it is a code convention indicating that the method returns a boolean value. As for the end keyword, it is once to indicate the end of the if block and once to indicate the end of the method.

Allison Hanna
Allison Hanna
36,222 Points

Just as a fun note, you can also write only two cases instead of four if you use command.upcase (with "Y" or "YES") or command.downcase (with "y" or "yes").