Solution: Implement Letter Guessing Game
Go over the implementation of the letter guessing game.
We'll cover the following...
We'll cover the following...
Letter Guessing Game
secret_word = "football"
guessed_word = '_' * secret_word.length
attempt = 0
print "My secret word: "
while secret_word != guessed_word
puts guessed_word.chars.join(" ")
attempt += 1
print "Guess a character that appears in the secret word: "
guess = gets.chomp
print "Try #{attempt}: "
secret_word.length.times do |index|
if secret_word[index] == guess
guessed_word[index] = secret_word[index]
end
end
end
puts guessed_word.chars.join(" ")
puts "Correct!", "You got it in #{attempt} tries"
The letter guessing game
Explanation
Line 8: ...