Returning the Final String—Er, "Thtring" .gsub! method doesn't work with 'else' statement


When I run my code and enter a string that has an ‘s’ entered, I get no return output. But if I add a string without an ‘s’ I get the ‘else’ returning the string output I added to the print method. If I remove the ‘else’ statement from my code and enter a string with an ‘s’ the gsub! method works and replaces the value with th.

Here is my code:

print "Enter your string:"
user_input = gets.chomp

if user_input.include? "s"
user_input.gsub!(/s/, “th”)

print" No ‘s’ found"

puts " Your string output #{user_input} "

Thanks for any help.


Be sure the input you enter contains at least one uppercase letter.


I found the issue. I entered “end” after the “input” statement, it should be entered before.


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