Recall the Wrong Proposals
Learn to improve interactivity by implementing additional functionalities.
We'll cover the following...
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 doinfo = word_info(hidden_word, found_letters)puts infoputsprint "Wrong letters: "puts wrong_letters.sort.uniq.join(" ")putsprint "Give me a letter: "answer = getsanswer = answer.chomp.downcaseif answer == 'stop'exitendif answer.length > 1puts "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)elsefound_letters << answerendelseputs "Invalid letter"wrong_letters << answer.upcaseendend
Let’s have a look at the ...