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

Ruby keeps telling me that I can't assign true to a variable. What am I doing wrong?

It also adds that there is an unexpected '=', but when I took it out, it just said it didn't work.

ruby.rb
def valid_command?(command)
  gets.chomp.downcase
  if (command == y) || (command == yes)
    valid_command? = true
  end
end

2 Answers

Nyra,

There are multiple ways to address issues when programming. I don't remember if this is how I went about it the first time, but here is one way to achieve the desired result:

def valid_command?(command) if command.downcase == "y" || "yes" return true end end

An important concept to remember is == and = are not the same thing. == tests whether conditions on each side of it are equal, whereas = assigns a variable Hope this is helpful! Thank you for the question.

Hi Nyra,

Great efforts but find some minor issues, you haven't put another strings capitals like "Y" or "YES", notice there is no double-quotes " " to make them strings. This challenge requires you to have ALL the strings without using downcase and also it should return true.

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

---------------OR----------------------------

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

Either way you can use above, on the bottom is simply shortcut in one line. Hope that helps. :)

-Salman