rand_num = rand(1..100) + 1
puts "I have generated a random number for you to guess. Please enter your guess."
attempts = 0
guess = ""
until guess == rand_num || attempts == 100 do
#Level 1
guess = gets.chomp.to_i
if guess.to_i != rand_num
puts "Please guess again."
end
#Level 2
guess = gets.chomp.to_i
if guess.to_i > rand_num
puts "Your guess, #{guess}, is greater than the random number. Please guess again."
elsif guess.to_i < rand_num.to_i
puts "Your guess, #{guess}, is less than the random number. Please guess again."
end
#Level 3
puts "Note the following updated game instructions:\nEnter 'c' to see the random number or enter your own guess."
guess = gets.chomp.to_s
if guess == 'c'
puts "The random number is #{rand_num}. Enter enter a number to continue.\n Please enter another number:"
guess = gets.chomp.to_i
else guess.to_i != rand_num
puts "That number does not match. Here's another hint."
end
if guess != rand_num
if rand_num.even?
puts "The random number is divisible by two. Please, guess another number:"
else rand_num.odd?
puts "The random number is not divisible by two. Please guess another number:"
end
end
attempts += 1
end
if guess == rand_num
puts "Yay! You win the game!"
end