Improve the Proposal Check
Understand how to enhance input validation in a Ruby hangman game by converting uppercase letters to lowercase and rejecting inputs longer than one letter. Learn to apply string methods like chomp and downcase, and control flow using conditional statements to improve user input handling.
We'll cover the following...
Towards the end of the last lesson, we identified the following unwanted behaviors:
- Giving an uppercase letter doesn’t work.
- Giving two letters instead of one results in a two-letter comparison.
Handle the uppercase letter
Let’s understand the scenario first and try to fix it.
We add one more process at line 9, right after giving a name (answer) to the letter that the user proposed.
We send the chomp message to remove the carriage return character and send the downcase message to the produced result. As we said before, every action produces a result to which we can send another message. Here, ...