6. Setting Up the 'Else' Branch



If I type anything containing an s in the console, the code works and I can move on. However, if I type anything that does not contain an s, I receive the following error messages:

undefined method 'include?' for nil:NilClass
Oops, try again. Your code doesn't look quite right. Check the first exercise if you need help!

print "Thay Thomething:"
user_input = gets.chomp
user_input = user_input.downcase!

if user_input.include? "s"
    user_input.gsub!(/s/, "th")
    puts user_input
    puts "There are no \"s\"'s in your string..."


Problem comes from here

user_input = user_input.downcase!

It'll return Nil if no changes were made.If you type a string that is lowercase then you'll get that error.remove the ! or do the following.

user_input.downcase! # don't store to user_input

Run this

print "type lowercase string"
user_input = gets.chomp

puts user_input.class
puts c.class


Thanks, that totally worked.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.