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

Ewelina Sobora
Ewelina Sobora
5,604 Points

The or operator. What's wrong with my code?

def valid_command?(command) puts "Put the command yes or no: " command = gets.chomp.downcase if (command == "y") || (command == "yes") || (command == "Y") || (command == "YES") return "true" else return "false" end
end

ruby.rb
def valid_command?(command)
  puts "Put the command yes or no: "
  command = gets.chomp.downcase
  if (command == "y") || (command == "yes") || (command == "Y") || (command == "YES")
    return "true"
  else
    return "false"
  end  
end

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Nothing is wrong with your or evaluation. However, Treehouse is going to send in something to your function which will reside in the local command variable. You use the puts to output a prompt to the user and then set the command variable equal to what the user typed in. But this overwrites what Treehouse has sent. So now, it can't properly evaluate your code.

It's important to remember that when doing these challenges to try not to do anything the challenge doesn't explicitly ask for. To fix this, remove these two lines:

 puts "Put the command yes or no: "
 command = gets.chomp.downcase

Hope this helps! :sparkles: