Setting Up the 'If' Branch, Part 1


I'm not stuck but curious about certain syntax for this exercise. When I did (1) & (3), it works. But when I tried (2), I had an error. Any explanations?


user_input = gets.chomp


user_input = gets.chomp.downcase!


user_input = gets.chomp.downcase


.downcase! works fine for me (Chrome Version 58.0.3029.110 (64-bit))

Which browser are you using?


I use chrome. when using the syntax:

user_input = gets.chomp

works fine but when using:

user_input = gets.chomp.downcase!

acted goofy and kept getting an error. Then tried:

user_input = gets.chomp.downcase

and it worked. No clue why lol


.downcase! will modify the string in place, whereas .downcase will return a new string.

If your string is already in lowercase, it will return nil – and you'll get the error you're getting.

- If your user input is: this is a string, you'll get a nil return error (as the entire string is already lowercase)
- If your user input is: This is a string (or THIS IS A STRING), it will work.

And I think this works regardless...

user_input = gets.chomp

... because the user input has already been assigned to variable user_input, and then .downcase! is applied to it.

Hope that answers your question?


Yea, I believe it does. Thank you!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.