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

Yuichi Narisawa
Yuichi Narisawa
19,548 Points

How can I get this code right?

I'm stack again. I'm not sure why this code won't work. Any advise would help. Thanks!

ruby.rb
def valid_command?(command)
  command = get.chomp
  if (command == "y" || "yes")
    command = true
   elsif (command == "Y" || "YES")
     command = true
  end
end

1 Answer

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

Hi there! Your could would actually work if you just removed this line:

command = get.chomp

Treehouse is sending in information that gets stored in the command variable specified in the parameters. You take that variable and immediately overwrite what they just sent in by using the get.chomp.

However, your code could still be made a bit cleaner if it looked like this:

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

It's perfectly ok to put more than 2 conditionals in one line. Hope this helps! :sparkles:

Yuichi Narisawa
Yuichi Narisawa
19,548 Points

Hi, Jennifer! Thank you for your quick response. I finally get through the challenge!! :)