AI Features

Improve the Proposal Check

Learn to improve the behavior of the program by incorporating additional checks.

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.

hidden_word = "hello"
puts "_ _ _ _ _"
puts
print "Give me a letter: "
answer = gets
answer = answer.chomp.downcase
if hidden_word.include?(answer.chomp)
puts "The letter is part of the hidden word"
else
puts "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. ...