|| within an `if` statement`


#1

I couldn't get this to work:

print "Input:"
user_input=gets.chomp

if  user_input.include?  "s" || user_input.include?  "S"
...

I resorted to

print "Input:"
user_input=gets.chomp.downcase
    
if  user_input.downcase.include?  "s"
...

But I don't understand what was wrong with my previous version. Ideas?

Here's what Ruby complained about:

(ruby):3: syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'
...user_input.downcase.include?  "s"
...                               ^
(ruby):7: syntax error, unexpected keyword_else, expecting $end

#2

It's just a problem of syntax.

Try this:

if user_input.include?("s") || user_input.include?("S")

#3

Aha, thanks.

I wonder why they didn't teach us this more robust version in the first place.