8/8 What am I missing?


I'm trying to complete all of the suggestions in the instruction panel for Congratulationth!
So far I have successfully re-prompted the user for a string, and made it so that instances of 'ce' are replaced with the.
The problem came when I tried to keep the user's original upper and lowercase choices. I decided to delete user_input.downcase! and add a few more elsifs to take care of the eventualities for capital S and CE. I ended up with an error that states:

(ruby):17: syntax error, unexpected ')', expecting keyword_then or ';' or '\n'

Here is the code:

//Obtains string from user
print "May I pleathe have a thtring?"
user_input = gets.chomp

//Continues to prompt user for string
while user_input.length == 0
print "May I pleathe have a thtring?"
user_input = gets.chomp

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

//lowercase ce
elsif user_input.include? "ce"
user_input.gsub!(/ce/, "the")

//uppercase S
elsif user_input.include? "S"
user_input.gsub!(/S/, "Th")

//uppercase CE
elsif user_input.include? "Ce")
user_input.gsub!(/Ce/, "The")

puts "There is no 's' sound in your string!"

puts "#{user_input}"

Note: I used # for my comments in my original code, not //

Thanks in advance!


This line is your problem.


Thank you! That really helps!


Hey, just a quick FYI. If you write your code like this then it will stop checking after your first if or else statement is true. for instance if you had something such as “Cedric the entertainer is awesome” the result would be “Cedric the entertainer ith awethome”.

I re-wrote the if and else statements as follows.

if user_input.include? “s” || “ce” || “S” || “Ce”
user_input.gsub!(/s/, “th”)
user_input.gsub!(/ce/, “the”)
user_input.gsub!(/S/, “Th”)
user_input.gsub!(/Ce/, “The”)

By using an ‘or’ in the if statement then your code will check for all of these instances simultaneously rather than until it finds one to be true.