FAQ: Thith Meanth War! - Congratulationth!


#1

This community-built FAQ covers the “Congratulationth!” exercise from the lesson “Thith Meanth War!”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Congratulationth!

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#3
print "What's uuuup?"
user_input = gets.chomp
if (user_input.downcase.include? "s") || (user_input.downcase.include? "ce") || (user_input.downcase.include? "ci") 
  user_input.gsub!( /[sS]/ , "s" => "th" , "S" => "TH")
  user_input.gsub!( /ce/ , "the" )    
  user_input.gsub!( /Ce/ , "The" )  
  user_input.gsub!( /CE/ , "THE" )  
  user_input.gsub!( /ci/ , "thi" ) 
  user_input.gsub!( /Ci/ , "Thi" )  
  user_input.gsub!( /CI/ , "THI" )  
  print "Your string is #{user_input}"
elsif user_input.empty?
  puts "Try again"
else
  puts "No letters to change, try again"
end

:white_check_mark: Add an additional if statement to re-prompt the user for input if they don’t enter anything


:white_check_mark:Think about how you might account for words in which the letter “c” sounds like an “s”
(Solved-ish. But I wanted to see if there could be a way to solve it using one line of .gsub

user_input.gsub!( /[sc]/ , "th")

Problem:
If you the user writes “I’m fine, come on!” , the result is “No letters to change, try again”, which is fine.
However, if the user writes “I’m super fine, Cecilia! come on!” , the result is "I’m thuper fine, thethilia! thome on!"

So, I tried writing:

user_input.gsub!( /[scei]/ , "s" => "th" , "ce" => "the" , "ci" => "thi")

But for some reason it doesn’t allow substituting a sequence of more than one character? Like it allows:
"s" => "loremipsum" but the other way around it returns nil
The result is "I’m thuper fine, cilia! comeon!"


:white_check_mark:Think about how you might preserve the user’s original capitalization
I tried to do something with .casecmp but I couldn’t come up with anything :cold_sweat:
I’m not 100% happy about this, cause I feel like there could be a better way of writing this.
Maybe having a way to say substitute “c” to “th” with the exception of when it comes after “-a”, “-o” and “-u”?

If anyone knows a way around this, please let me know!