My goal is to create a game of hangman. I wrote code similar to this:
c = []
players_guess = gets
b = "example"
b.scan(/./) {|letter| c << letter}
c.each do |letter|
if letter == players_guess
puts letter
else
puts "*"
end
end
The code checks if the player guessed the right letter from the password hidden in variable c
, and then displays the password hidden behind the *
s and only revealed guessed letters. But when I run the program, the result is always the same, it displays players_guess
, and then gives seven *
. What is wrong here?