...

/

Recall the Wrong Proposals

Recall the Wrong Proposals

Learn to improve interactivity by implementing additional functionalities.

Storing the wrong letters

Displaying the number of letters of the hidden word and the found letters is not enough to help the player. It’s also useful to show the wrong letters that they proposed. To do this, we are going to store the wrong letters in the same way as we accumulate the correct letters in a collection.

Press + to interact
require_relative "word_info"
hidden_word = "fuchsia"
found_letters = []
wrong_letters = []
loop do
info = word_info(hidden_word, found_letters)
puts info
puts
print "Wrong letters: "
puts wrong_letters.sort.uniq.join(" ")
puts
print "Give me a letter: "
answer = gets
answer = answer.chomp.downcase
if answer == 'stop'
exit
end
if answer.length > 1
puts "You must give only one letter!"
elsif answer.empty?
elsif hidden_word.include?(answer)
puts "The letter is part of the hidden word"
if found_letters.include?(answer)
else
found_letters << answer
end
else
puts "Invalid letter"
wrong_letters << answer.upcase
end
end

Let’s have a look at the ...