I made a game in lua where a number between 1 to 10 is generated at random and the player needs to guess the number. The only number that seems to be generated, however, is 9. Here is the code:
number = math.random(1, 10)
function guess(number)
print("Please input a number between 1 and 10: ")
input = io.read()
if tonumber(input) < number then
print("Too low!")
guess(number)
elseif tonumber(input) > number then
print("Too high!")
guess(number)
elseif tonumber(input) == number then
print("You got it!")
end
end
guess(number)
A random number between 1 and 10 should be created with math.random() and stored in the number variable, but it seems that the number that is generated is always 9. What could be causing this, and how can I fix it?