Using Sinatra, for whatever reason, the result if number > 1000, is NOT outputting to browser. It immediately shows "It took 0 tries to guess your number 10000." for example. So while the if statement works by NOT executing the until loop, it won't display the output to the browser. Hopefully I'm just doing something really silly.
SIMPLY: "Number must be under 1000." # This doesn't output to browser... WHY!?
Does NOT work...
Extra credit: What is the easiest way to store the last attempted guesses so that rand ONLY tries NEW values and compares once per number. e.g., Make /lottery/10 impossible to have more than 10 guesses.
Code Below
get '/lottery/:number' do
i = 0
guess = 0
number = params[:number].to_i
if number > 1000 then
"Number must be under 1000." # This doesn't output to browser... WHY!?
else
until number == guess do
guess = rand(number) + 1
puts "Guess: #{guess} | Attempt: #{i}"
i +=1
end
end
"It took #{i} tries to guess your number #{number}."
end