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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
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).
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.
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.
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.
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
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?
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.
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
user_input.downcase!
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