I'm attempting to make a random number guessing game in Ruby. I'm rather new so perhaps the answer is obvious but why won't this work?
number = rand(5)
choice = 9999
while number != choice do
puts "Guess the number #{number}"
choice = gets.chomp
end
puts "You guessed Correctly! #{number} was the correct number."
As you can see I limited it to numbers between 0 and 4. Then the while loop runs while the guess made by the user is different from the random number generated. However, even when the user enters the correct number, the while loop continues looping. As you can see I've even printed the generated number so I know which to guess.
Any idea what's going wrong here?