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


#1

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
user_input.downcase!

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

else
print" No ‘s’ found"

puts " Your string output #{user_input} "
end

Thanks for any help.


#2

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


#3

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


#4

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