I don't know what is wrong with this code, but it certainly is


#1

print "an input please......"
user_input = gets.chomp
user_input = user_input.downcase!
if user_input.include? 's'
user_input.gsub!(/s/, "th")
else print 'No s!'
end

I typed in this and the error message cried out


#2

Is this lesson 6? That's what it looks like. What error message are you getting?


#3

Also, please edit your opening post to reveal the code sample. Use the following technique:

```

Your code here

```

The back-tick is on the same key as the tilde (~) left of the [1] key (on most keyboards).

Your code will look like this:

print "an input please......"
user_input = gets.chomp
user_input = user_input.downcase!
if user_input.include? 's'
    user_input.gsub!(/s/, "th")
else print 'No s!'
end

#4

After testing and doing a little reading, it turns out that if the input is all lowercase, then the output from .downcase! is 'nil'. There must be at least one uppercase letter in the input.


#5

undefined method `include?' for nil:NilClass

is what the error message says


#6

If the input has no uppercase letters, this error occurs. Try changing downcase! to downcase. What happens then?


#7

a = 'downcase'
b = a.downcase!
puts b            # nil         # causes error on include?
puts a            # downcase
a = 'DownCase'
b = a.downcase!
puts b            # downcase
puts a            # downcase
a.upcase!
puts b            # DOWNCASE    # b is a
puts a            # DOWNCASE
a.downcase!
puts b            # downcase
puts a            # downcase

#8

hey, hi that one just helped me, thank you for having it there!! :slightly_smiling: