RosettaCodeData/Task/Guess-the-number-With-feedback/LiveCode/guess-the-number-with-feedback-1.livecode
2016-12-05 23:44:36 +01:00

29 lines
847 B
Text

command guessTheNumber lowN highN
local tNumber, tguess, tmin, tmax
if lowN is empty or lowN < 1 then
put 1 into tmin
else
put lowN into tmin
end if
if highN is empty then
put 10 into tmax
else
put highN into tmax
end if
put random(tmax - tmin + 1) + tmin - 1 into tNumber
repeat until tguess is tNumber
ask question "Please enter a number between" && tmin && "and" && tmax titled "Guess the number"
if it is not empty then
put it into tguess
if tguess is tNumber then
answer "Well guessed!"
else if tguess < tNumber then
answer "too low"
else
answer "too high"
end if
else
exit repeat
end if
end repeat
end guessTheNumber