FAQ: Thith Meanth War! - Congratulationth!

Thank you for replying

Hi can someone help me. I am trying to enter another if function to reprompt the user to enter input.

My codeis below;

print "Please type: "
user_input = gets.chomp
user_input.downcase!
if user_input.empty?
print "You entered no information, please type: "
user_input = gets.chomp
user_input.downcase!
end

if user_input.include? “s” || “ce” || “c” || “si”
user_input.gsub!(/s/,“th”) && user_input.gsub!(/ce/, “th”) && user_input.gsub!(/c/, “th”) && user_input.gsub!(/si/, “th”)
else
print “Nothing to do here”
end

puts “#{user_input}”

With this code I get - You entered no information, please type: Nothing to do here - which is a merge of my final “else” string and the second prompt. Can anyone see what I am doing wrong

Hi beta,
Unfortunately I am unable to replicate you results. If the problem is still occurring try refreshing the page and/or logging in and out.

Hi,
I am also learning. You must call again to the variable, try this:

print "Please type: "
    user_input = gets.chomp
    user_input.downcase!

if user_input.empty?
    puts "You entered no information, please type: "
    user_input = gets.chomp
    user_input.downcase!
end    

if user_input.empty?
    puts "You entered no information, please type: "
    user_input = gets.chomp
    user_input.downcase!
end

if
    if user_input.include? ("s")
#another way, to replace
        user_input.replace "th"
        print "Word '#{user_input}'"
    elsif user_input.include? "ce"
        user_input.gsub!(/ce/, "th")
        print "Word '#{user_input}'"
    elsif
        user_input.include? "c"
        user_input.gsub!(/c/, "th")
        print "Word '#{user_input}'"
    elsif user_input.include? ("si")  
        user_input.replace "th"
        print "Word '#{user_input}'"
    else
        print "Nothing to do here"
    end
end

You do realize that the entire if block will be ignored unless there’s “s” right?

Thank you for this, it helped me !
If I may add my 2 cents:
This definitely works if you want to capitalize the Daffy Duckified string as in having the first letter of the string as a capital letter. But it won’t “preserve the user’s original capitilization”.
The other problem I had was that “ce” was only replaced by “th” when the string actually contained an “s” as well.
So here would be my solution to that problem:

print "pleathe enter a thtring: " user_input= gets.chomp user_input.downcase! if user_input.empty? print "You didn't enter any word. Please enter some words: " user_input2= gets.chomp user_input2.downcase! if user_input2.include?("s") || user_input2.include?("ce") user_input2.gsub!(/s|ce/, "th") puts "Your Daffy Duckified string is: #{user_input2.capitalize!}" end elsif user_input.include?("s") || user_input.include?("ce") user_input.gsub!(/s|ce/, "th") puts "Your Daffy Duckified string is: #{user_input.capitalize!}" else puts "Nothing to daffy duckify here, please enter at least a word with an sssss sound in it: " user_input3= gets.chomp user_input3.downcase! if user_input3.include?("s") || user_input3.include?("ce") user_input3.gsub!(/s|ce/, "th") puts "Your Daffy Duckified string is: #{user_input3.capitalize!}" end end