Improve the Proposal Check
Learn to improve the behavior of the program by incorporating additional checks.
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.
Press + to interact
hidden_word = "hello"puts "_ _ _ _ _"putsprint "Give me a letter: "answer = getsanswer = answer.chomp.downcaseif hidden_word.include?(answer.chomp)puts "The letter is part of the hidden word"elseputs "Invalid letter"end
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. ...