FAQ: Thith Meanth War! - Downcase!

This community-built FAQ covers the “Downcase!” 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 Downcase!

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!

What are the uses of the exclamations and question marks after calling methods on strings while getting user input?

I have the same question!

By using an exclamation point after calling a method you modify the original object its called on. For example

original = "my string"
puts original.upcase      #puts "MY STRING"
puts original                    #puts "my string"
puts original.upcase!     #puts "MY STRING"
puts original                   #puts "MY STRING"

If we don’t use the exclamation mark the original method will not be changed. You can see that the “.upcase” does not change “original”. However, by using the exclamation mark we edit the original string/method as seen by the repeat of “MY STRING”.

The question mark acts as an if/else statement and tells the method to return a Boolean value (true or false).

num = [1.43, 2, 3.1, 4, 5, 6, 7.5, 8, 9.8, 10]
num.each  { |n|
  puts "#{n} >> #{n.is_a? Integer}"

The code above checks if each number in number in the “num” array is an integer (a whole number) and returns true if so. Try running it if you want to see what I mean.


I’m sorry it’s still not clear to me too with the purpose of the !
in your example

original = “my string”
puts original.upcase #puts “MY STRING”
puts original #puts “my string”
puts original.upcase! #puts “MY STRING”
puts original #puts “MY STRING”

Do you mean thanks to the .upcase! , the original will be now always in UPCASE and without the ! it will be basically a “one shot” change?

what does "Call the .downcase! method on user_input" mean. pls help

Hello, @ruby3535816482, and welcome to the Codecademy Forums!

You have a variable named user_input that will contain what the user enters in response to a prompt while the program is executed. We need to have all the letters that were entered be stored in lowercase. If any letters included in whatever was entered are in uppercase, we want them to be converted to lowercase, and the result saved in the variable user_input. In other words, the conversion should be performed in place.

Here’s how we do it:


Not sure what is wrong with the code in question.

You haven’t shown what error message feedback is given at the bottom. Your code looks correct, but do remember that after you run the code, you must click on the console window (you may have to click more than once), type in something and press enter. If you don’t do that or take too much time, you will get an execution expired error.

Thanks for the reply. It was just as simple as typing something into the console window, thanks for the help!

1 Like

Hi, I did exactly that and with the same code but it still does not accept it after typing in something and pressing enter.

Perhaps you ran out of time. If you take too long to enter an input, you will get the execution expired error. After hitting “Run”, you need to click in the console window to highlight that window (you may need to click more than once). Then you must type something and press the enter key on your keyboard. If you take too long to do all the above, then you will see the execution expired message. If you do it reasonably quickly, it should work. Your code looks correct.

Thank you, this did not solve my issue so just got solutions as no matter how fast I typed, it always gave me errors. Maybe it is a bug? It starts here and then ends at the end of the entire lesson.

Manually code the user_input and be sure there is at least one capital letter or .downcase! will change it to Nil. Suggest don’t use the bang operator. Use the assignment, instead.

user_input = "here's a string for testing".downcase

Edited typos (mtf)`

1 Like

Hello, I inputted the correct code but I’m not understanding it. By putting user_imput.downcase! shouldn’t whatever the user’s input was become in lowercase?

The user’s input does become lowercase. You can confirm this by adding a puts statement like so:

puts "What is your name?"
user_input = gets.chomp
puts user_input

Now, you will see lowercase salam appear on the screen.

Oh that makes sense! I forgot to add a puts statement for it to actually appear, thanks!

When using the bang! operator, the letter case will change only if there is at least one capital letter, otherwise the string will become, Nil (not even a string). The operation is in place. The result of the operation is Nil if nothing is changed. Be mindful of this scenario.

As a general rule, I always use assignment, which the bang operator does not support.

user_input = gets.chomp.downcase

I think it depends on how we are using the bang operator.
For example, suppose we use the code

puts "What is your name?"
user_input = gets.chomp
puts user_input

This will work regardless of whether the string entered has at least one uppercase letter OR even if the string is completely lowercase. If the user typed in salam, then user_input.downcase! will not do anything. It won’t replace the string with Nil either.

Contrast this with the snippet

puts "What is your name?"
user_input = gets.chomp
puts user_input.downcase!

This is liable to create problems and is a bad idea. If the entered string is SALAM or saLam, then this will work just fine. But, if the user entered a completely lowercase string like salam, then using the bang operator doesn’t make any changes to the original string and the result of the operation is Nil. Hence, the statement puts user_input.downcase! will not show any output. However, the original string is still preserved in the variable user_input. This can be confirmed by using a puts statement.

puts "What is your name?"
user_input = gets.chomp
puts user_input.downcase!   // Will print Nil if string is completely lowercase
puts user_input            // Will print the lowercase string

It’s very likely one has been caught up in suspect usage scenarios, and that more from memory now.