I am very new in Ruby and trying to have a randomly selected color from the array I have an array with 4 colors: Red, blue, white and pink I would like that a color has been selected and displayed randomly and everytime different color is printing
My code: (doesn't work)
@colors =["blue", "orange", "red", "white"]
#random_color = colors[rand(0..(colors.length - 1))]
random_color = rand(0..(@colors.length - 1))
print random_color
puts "Your choice: >"
guess = $stdin.gets.chomp
guesses = 0
while guess != random_color && guesses < 3
puts "Try again. You have to go out"
guesses += 1
print random_color
puts "Your choice: >"
guess = $stdin.gets.chomp
end