Ok,so as a little practice I’ve decided to come up with a Guessing Game
where the user is able to guess a number, and if it the same as the
randomly generated number by the computer, he gets a message that says a
little hooray message. That part is done, and completed, but now I need
help
with tracking the amount of entries he makes in gets
Here is my current code:
random_number = rand(10)
puts ‘Can you guess the number?’
puts ‘Select a number from 1-10 please’
players_number = gets.chomp
while players_number.to_i != random_number.to_i
while players_number.to_i < random_number.to_i
if players_number.to_i < random_number.to_i
puts ‘Sorry your to low’
puts ‘_________________’
random_number = rand(10)
puts 'Can you guess the number?'
puts 'Select a number from 1-10 please'
players_number = gets.chomp
end
end
while players_number.to_i > random_number.to_i
if players_number.to_i > random_number.to_i
puts ‘Sorry your to high’
puts ‘__________________’
random_number = rand(10)
puts 'Can you guess the number?'
puts 'Select a number from 1-10 please'
players_number = gets.chomp
end
end
while players_number.to_i == random_number.to_i
if players_number.to_i == random_number.to_i
puts ‘Congratluations! You Win!’
puts ‘_________________________’
random_number = rand(10)
puts 'Can you guess the number?'
puts 'Select a number from 1-10 please'
players_number = gets.chomp
else
end
end
end
Can anyone help me with tracking the amount of entries he makes? Thank
you.